左侧的android布局图像和右侧的两个文本块

时间:2016-08-22 13:51:20

标签: android xml layout android-linearlayout android-layout-weight

我想要这样的布局 Layout where an image at the bottom and two text block at right

这是一个非常简单的布局,左边是图像,右边是两个文本块。我知道如何在html和CSS中执行此操作,但不知道如何在XML中执行此操作。向左或向右浮动元素的属性是什么?现在,如果我添加一个图像和两个文本块,则不会显示第二个文本块。

3 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>

答案 2 :(得分: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>

自己编辑:)

相关问题