好吧,我想做的是:将 ImageView 设置在右侧,而 3 个 TextView 将位于相对于图像的左侧。使用以下 XML 代码, ImageView 位于左侧,3 个 TextView 位于 ImageView 的右侧。
现在是这样的:
正如我所说,我希望图像在右侧对齐,3 个 TextView 在图像左侧对齐。
所以这是当前的 xml:http://pastebin.com/r68S1QKv
如果我将 LinearLayout 更改为 RelativeLayout(这样我就可以使用 alignParentRight = true),textview 会相互堆叠并且不会垂直显示。
有什么建议吗?
编辑: 看起来我还没有阐明想要的外观,这是我想要的示例:
最佳答案
使用此代码。使用 RelativeLayout 作为父级并将 android:layout_alignParentRight="true"分配给他的 child ,这会将您的所有 View 设置为右侧。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/row_title"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hey1" />
<TextView
android:id="@+id/row_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hey2" />
<TextView
android:id="@+id/row_postcode_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hey3" />
</LinearLayout>
<ImageView
android:id="@+id/icon"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
关于java - 右对齐我的观点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12450014/