java - 右对齐我的观点

标签 java android xml user-interface alignment

好吧,我想做的是:将 ImageView 设置在右侧,而 3 个 TextView 将位于相对于图像的左侧。使用以下 XML 代码, ImageView 位于左侧,3 个 TextView 位于 ImageView 的右侧。

现在是这样的: enter image description here

正如我所说,我希望图像在右侧对齐,3 个 TextView 在图像左侧对齐。

所以这是当前的 xml:http://pastebin.com/r68S1QKv

如果我将 LinearLayout 更改为 RelativeLayout(这样我就可以使用 alignParentRight = true),textview 会相互堆叠并且不会垂直显示。

有什么建议吗?

编辑: 看起来我还没有阐明想要的外观,这是我想要的示例:enter image description here

最佳答案

使用此代码。使用 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/

相关文章:

android - 如何在 Activity 中使用 navGraphViewModels(不在 Fragment 中)

java - Java类中的变量@XmlElement(nillable = true)之前是什么意思

java - LibGDX FreeTypeFontGenerator

java - 处理 InputMismatchException 时文本菜单中出现无限循环

android - 警报对话框生成器停止响应

Android Vector Asset Studio : Import SVG and use ID as Name

c# - 使用 List<> 将 Xml 字符串反序列化为对象

android - 背景图像不只显示蓝色方 block

java - 将字符串中的所有字符转换为不同的转义格式(Java)

java - Swagger CodeGen 生成带有多个 try catch 的代码 ApiController.java