【发布时间】:2017-12-16 17:08:05
【问题描述】:
我有一个 XML 表示某个应用程序中的单行,包含姓名、等级和图片。
姓名+等级垂直设置在左侧,我的目的是让图片位于右侧。
我正在尝试使用RelativeLayout,以便将ImageView 与屏幕右侧对齐,据我所知这是正确的做法,但它隐藏了我的其他布局 -
使用时只有图像视图可见。
尝试更改布局宽度\高度以匹配父级,但没有帮助。
我误解了什么?我在这里的错误用法是什么?
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_line"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#FF00">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="start|center">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_example"
android:textSize="25sp"
android:textStyle="bold"
android:textAlignment="center"
android:maxLines="1"
android:ellipsize="end"
android:padding="2dp"
android:background="@color/transparent"
android:focusable="false">
</TextView>
<TextView
android:id="@+id/tv_grade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="@string/tv_example"
android:textSize="20sp"
android:textStyle="bold|italic"
android:textAlignment="center"
android:maxLines="1"
android:ellipsize="end"
android:padding="2dp"
android:background="@color/transparent"
android:focusable="false">
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/iv_pic"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
【问题讨论】:
标签: android android-layout android-linearlayout android-relativelayout