0

Я хочу, чтобы макет, как этот Layout where an image at the bottom and two text block at rightандроид макет изображения слева и два блок текста в правой

Это очень простой макет с изображением на левые и два текстовых блоках справа. Я знаю, как это сделать в html и CSS, но не знаю, как это сделать в XML. Каковы свойства для размещения элементов слева или справа? Прямо сейчас, если я добавляю изображение и два текстовых блока, второй текстовый блок не отображается.

ответ

0
<?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"> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"/> 

</LinearLayout> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

Редактировать это самостоятельно:)

0

Вы можете использовать относительный макет для этого:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent"> 
    <ImageView android:id="@+id/img" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:src="@drawable/ic_clear"/> 
    <TextView android:id="@+id/text1" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@+id/img" 
      android:layout_toRightOf="@+id/img" 
      android:layout_width="match_parent" 
      android:text="text 1"/> 
    <TextView android:layout_below="@+id/text1" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@+id/img" 
      android:layout_toRightOf="@+id/img" 
      android:layout_width="match_parent" 
      android:text="text 2"/> 
</RelativeLayout> 
1

Попробуйте этот код, я тестировал:

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

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:layout_weight="1"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center"/> 

</LinearLayout> 

+0

ImageView не обязательно должен находиться внутри LinearLayo ет. Вы могли бы просто удалить родительский linearLayout и вместо этого присвоить значение weight-property. –

+0

Вы правы. Я отредактировал свой ответ – Ricardo

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