【问题标题】:Android layout alignment not behavingAndroid布局对齐不起作用
【发布时间】:2012-06-11 21:56:59
【问题描述】:

这是结果,这不是我们想要的。文本应左对齐。复选框应向右对齐。超长的文本应该稍微压扁,以便为右侧的单选按钮留出空间。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:padding="5dp">

<TextView android:id="@+id/itemCaption"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true" 
    android:textSize="13dp"
    android:textColor="#feee"/> 

<RadioButton
    android:id="@+id/itemRadioBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:layout_marginRight="5dp"
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_toRightOf="@+id/itemCaption"
    android:text="" />

</RelativeLayout>

如何修复它以按需要显示?

【问题讨论】:

    标签: android layout alignment android-relativelayout gravity


    【解决方案1】:

    你的线路

    android:layout_toRightOf="@+id/itemCaption"
    

    优先于你的行

    android:layout_alignParentRight="true"
    

    尝试删除 android:layout_toRightOf="@+id/itemCaption" 行!!!

    【讨论】:

    • 嗯?你粘贴了两次相同的东西
    • 这不会解决底部大段落文本的问题,它会渗入另一个单选框,而不是对齐到它的左侧
    • 在这种情况下,您可能必须有 2 个相对布局和父级相对布局中的文本视图才能解决此问题。每个单选按钮/标签对都有一个相对布局,并将最终的 textview 底部相对于最底部的内部相对布局。如果这没有帮助,我可能需要查看完整的 xml 文件以进一步帮助您。
    猜你喜欢
    • 2015-04-08
    • 1970-01-01
    • 2017-08-28
    • 2011-05-17
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多