2015-10-30 3 views
0

У меня есть JPG разных размеров.Выравнивание изображения вверх

Я создал пользовательское listview с изображением и двумя текстовыми изображениями.

Я хочу выровнять изображение в левом верхнем углу LinearLayout, но ничего не пробовал все, но ничего не работает.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/petPhoto" 
     android:layout_gravity="top|left" 
     android:layout_width="150dp" 
     android:layout_height="150dp" /> 

    <LinearLayout 
     android:background="#ff0000" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/petName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/petDescription" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

</LinearLayout> 

ответ

0

Попробуйте это

Изменение LinearLayout к RelativeLayout и добавить свойство alignParentTop к началу,

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="@dimen/card_padding" 
    android:background="@color/card_background"> 

    <ImageView 
     android:id="@+id/thumbnail" 
     android:src="@drawable/thumbnail" 
     android:layout_width="72dip" 
     android:layout_height="72dip" 
     android:scaleType="centerCrop"/> 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Card title" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:textAppearance="@android:style/TextAppearance.Holo.Medium" 
     android:layout_marginLeft="?android:attr/listPreferredItemPaddingLeft"/> 

    <TextView 
     android:id="@+id/description" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Card description" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:layout_below="@+id/title" 
     android:layout_marginLeft="?android:attr/listPreferredItemPaddingLeft" 
     android:textAppearance="@android:style/TextAppearance.Holo.Small"/> 

</RelativeLayout> 

Вывод кода, как это,

enter image description here

+0

Нет, не работает. Теперь изображение просматривается в центре. Он также не воспламеняется в верхней части каждой «строки» списка. Я хочу, чтобы изображение просматривалось слева - выравнивалось в верхнем и левом углу. – user2923955

+0

Я отредактировал изображение, пожалуйста, проверьте это, и я вставил свойство, alignParentLeft = "true" –

+0

Для лучшей справки, пожалуйста, поделитесь своим рисунком, как вам это нужно, поэтому я могу вести вас в соответствии с моментальным снимком. –

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