Android 相对布局缩放和对齐

标签 android android-layout android-imageview textview

我需要设计下面给出的 Andorid 布局,但是我无法正确处理定位。

enter image description here

这里是 View 部分的类型和我的约束:

  • A: ImageView ,固定宽度,固定高度,左对齐
  • B: TextView ,自动缩放宽度,固定高度
  • C: TextView ,自动缩放宽度,固定高度
  • D: TextView ,自动缩放宽度,固定高度
  • E: TextView ,自动缩放宽度,固定高度
  • F: ImageView ,固定宽度,固定高度,右对齐

我尝试了相对布局,但我无法处理最右边的 View (即 F)。那么这个布局的正确 XML 标记应该是什么?

最佳答案

相当简单。尝试这样的操作(为了节省空间,我省略了高度和宽度等其他内容):

    <RelativeLayout>

        <ImageView
            android:id="@+id/A"
            android:layout_alignParentLeft="true" />

        <ImageView
            android:id="@+id/F"
            android:layout_alignParentRight="true" />

        <LinearLayout
            android:id="@+id/container"
            android:layout_toRightOf="@+id/A"
            android:layout_toLeftOf="@+id/F"
            android:orientation="horizontal"
            android:weightSum="3" >

            <TextView
                android:id="@+id/B"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/C"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/D"
                android:layout_weight="1" />
        </LinearLayout>

        <TextView
            android:id="@+id/E"
            android:layout_toRightOf="@+id/A"
            android:layout_toLeftOf="@+id/F"
            android:layout_below="@+id/container" />

    </RelativeLayout>

关于Android 相对布局缩放和对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9181460/

相关文章:

android - 如何将数据从一个 xml 发送到另一个 xml 布局?

android - 如何从 Web 服务获取图像到 Android 应用程序?

java - Android - 在 ImageView 中交叉淡化多个图像

java - Android RecyclerView 内容在 notificationItemInserted 后未更新

java - 在android中的EdiTtext中删除/修改选定的文本

java - 颜色无法解析或不是字段

android - 在不移动叠加 View 的情况下裁剪和缩放图像,而不是在 ImageView 中移动图像

android - 编译错误: No resource found that matches the given name 'android:elevation'

android - 如何在 EditText 中输入数字时自动添加千位分隔符

Android 布局 - layout-normal vs layout