2016-06-23 2 views
0

У меня есть следующий дизайн, где я хочу, чтобы изображение моего левого пользователя, а затем текстовое изображение справа от изображения пользователя и изображения стрелки справа. Однако, по некоторым причинам, стрела не приходит в самый правыйImageView не выравнивается должным образом

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="6dip" 
    android:background="#FFFFFF"> 
    <ImageView 
    android:id="@+id/userimage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="6dip" 
    android:gravity="center" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/ic_person_black_24dp" 
    android:layout_gravity="center_vertical" /> 
    <LinearLayout 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="6dip"> 
    <TextView 
     android:id="@+id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:textSize="15dp" 
     android:textColor="#040404" 
     android:typeface="sans" 
     android:textStyle="bold" 
     android:text="Username_05" 
     android:singleLine="true" /> 
    <TextView 
     android:id="@+id/secondline" 
     android:text="Text" 
     android:layout_below="@id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10sp" 
     android:textColor="#000000" 
     android:singleLine="true" /> 
    </LinearLayout> 
    <ImageView 
    android:id="@+id/icon" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ic_keyboard_arrow_right_black" 
    android:layout_gravity="center_vertical" /> 
</LinearLayout> 

Вот мой выходной ток:

![enter image description here

Update 1:

enter image description here

+0

изменение layout_width к wrap_content КСТАТИ single_line является устаревшим Используйте max_lines = 1 – Enoobong

+0

fill_parent также не рекомендуется; используйте match_parent вместо – Eenvincible

ответ

1

I думаю, это потому, что вы используете android: layout_width = "match_parent" вместо обертывания содержимого.

Если вы используете линейный макет, вам нужно вес, чтобы использовать все пространство:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:local="http://schemas.android.com/apk/res-auto" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:padding="6dip" 
      android:background="#FFFFFF"> 
<ImageView 
    android:id="@+id/userimage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="6dip" 
    android:gravity="center" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/ic_person_black_24dp" 
    android:layout_gravity="center_vertical" /> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:padding="6dip"> 
    <TextView 
     android:id="@+id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:textSize="15dp" 
     android:textColor="#040404" 
     android:typeface="sans" 
     android:textStyle="bold" 
     android:text="Username_05" 
     android:singleLine="true" /> 
    <TextView 
     android:id="@+id/secondline" 
     android:text="Text" 
     android:layout_below="@id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10sp" 
     android:textColor="#000000" 
     android:singleLine="true" /> 
</LinearLayout> 
<ImageView 
    android:id="@+id/icon" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ic_keyboard_arrow_right_black" 
    android:layout_gravity="center_vertical" /> 
</LinearLayout> 
+0

В какой строке вы указываете? – hotspring

+0

Внутри двух текстовых полей, во втором вы используете fill_parent (это то же самое, что match_parent) – ldd

+0

Я сделал это, все тот же. – hotspring

2

Держите его просто. Используйте LinearLayout с горизонтально ориентации вместо RelativeLayout и добавить 1. ImageView 2. Другой LinearLayout с layout_weight = 1 и вертикальной ориентации, которая будет содержать два TextViews 3. ImageView

Извините за не размещение какого-либо кода. Я с мобильного телефона;)

+0

да, это лучше – ldd

+0

Я обновил свой вопрос на основе вашего подхода. Единственная проблема заключается в том, что правильный образ не подходит к самому лучшему. – hotspring

+0

На втором LinearLayout один с TextViews добавляет android: layout_weight = 1 –

1

Я думаю, что вы ищете что-то вроде этого

enter image description here

. Нет смысла создавать отдельный Imageview для размещения значков. Для достижения этого лучше используйте android:drawableLeft и android:drawableRight.

Ниже приведен пример кода:

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="left|center" 
     android:text="Testing" 
     android:drawableLeft="@drawable/ic_account_circle_black_24dp" 
     android:drawableRight="@drawable/ic_account_circle_black_24dp"/> 

Edit: Для многострочных:

enter image description here

+0

Да, это очень похоже. Мне нужны только две текстовые строки, а не одна. – hotspring

+0

Если вы используете 'android: text =" Testing \ n Part1 "', вы получите Part1 в новой строке. Вы всегда можете конкатрировать две строки и добавить новую строку между ними. Просто говорю. – driftking9987

+0

Проверьте обновленное изображение в ответе. – driftking9987

1

Во-первых, не используйте android:orientation на RelativeLayout, это свойство только для LinearLayout ,

Во-вторых, вы делаете круговые ссылки:

  • Имя пользователя имеет android:layout_above="@id/secondline"
  • второй линии имеет android:layout_below="@id/username"

Когда вы делаете, что система не знает, как сделать точку зрения, потому что они зависят друг от друга.

Попробуйте сделать это:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:padding="6dip" 
       android:background="#FFFFFF"> 
    <ImageView 
     android:id="@+id/userimage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="6dip" 
     android:layout_alignParentLeft="true"/> 
    <TextView 
     android:id="@+id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:textStyle="bold" 
     android:text="Username_05" 
     android:layout_toRightOf="@id/userimage" 
     android:singleLine="true" /> 
    <TextView 
     android:id="@+id/secondline" 
     android:text="Text" 
     android:layout_below="@id/username" 
     android:layout_toRightOf="@+id/userimage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:singleLine="true"/> 
    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"/> 
</RelativeLayout> 

Результат:

enter image description here

+0

Это дало мне тот же результат. разница не наблюдается. – hotspring

+0

Тогда я не понимаю, чего вы хотите. Это соответствует описанию, которое вы отправили, выполните синхронизацию перед установкой приложения с этими изменениями. –

+0

Я опубликовал результат –

0

Используйте код содержится в вашем вопросе, но изменить android:layout_width="match_parent" к android:layout_width="wrap_content" в ImageView вашей стрелки. Это должно привести к тому, что стрелка ImageView появится в полном порядке

1

Просто используйте layout_weight.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#FFFFFF" 
android:orientation="horizontal" 
android:padding="6dip"> 

<ImageView 
    android:id="@+id/userimage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_gravity="center_vertical" 
    android:layout_marginRight="6dip" 
    android:layout_weight=".1" 
    android:gravity="center" 
    android:src="@android:drawable/ic_menu_my_calendar" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="5" 
    android:orientation="vertical" 
    android:padding="6dip"> 

    <TextView 
     android:id="@+id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:singleLine="true" 
     android:text="Username_05" 
     android:textColor="#040404" 
     android:textSize="15dp" 
     android:textStyle="bold" 
     android:typeface="sans" /> 

    <TextView 
     android:id="@+id/secondline" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/username" 
     android:singleLine="true" 
     android:text="Text" 
     android:textColor="#000000" 
     android:textSize="10sp" /> 
</LinearLayout> 

<ImageView 
    android:id="@+id/icon" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical|right" 
    android:layout_weight="1" 
    android:src="@android:drawable/arrow_down_float" /> 
</LinearLayout> 

enter image description here

+0

В дизайнере это выглядит правильно. Но когда я запускаю его, я не вижу стрелы. Я использую активность как диалог. – hotspring

+0

Можете ли вы опубликовать изображение диалога? –

+0

См. Обновленное изображение – hotspring

Смежные вопросы