保证金不起作用

时间:2014-01-15 07:56:08

标签: android android-layout android-xml

我有以下XML文件来实现片段。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/two_third_width"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/extra_margin"
android:background="@drawable/found_item_bg"
tools:context=".FoundItemFragment" >

<TextView
    android:id="@+id/found_item_description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_margin="@dimen/small_margin"
    android:layout_marginRight="@dimen/extra_margin"
    android:textColor="@color/BlueText"
    android:textSize="@dimen/big_title_font" />

<TextView
    android:id="@+id/found_item_catnum_name"
    android:layout_width="@dimen/item_bg_width"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@id/found_item_description"
    android:layout_margin="@dimen/small_margin"
    android:layout_marginRight="@dimen/big_margin"
    android:background="@drawable/item_name_bg"
    android:text="@string/catalog_number"
    android:textSize="@dimen/found_item_font" />

<TextView 
    android:id="@+id/found_item_catnum_value"
    android:layout_width="@dimen/item_bg_width"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/found_item_catnum_name"
    android:layout_alignBaseline="@id/found_item_catnum_name"
    android:layout_margin="@dimen/small_margin"
    android:background="@drawable/item_value_bg"
    android:textSize="@dimen/found_item_font" />

    ...

</RelativeLayout>

无论我给TextView元素的右边距赋予什么值,我都会得到以下渲染: layout

第一个问题是found_item_description文本在某处消失了。主要问题是右侧的三个TextView应该在布局内部,而不是在右侧扩展。我已经尝试了layout_marginRight的各种值,但是各种值似乎都没有效果。我假设某些东西压倒或抵消了保证金价值,但我不明白它可能是什么。

2 个答案:

答案 0 :(得分:0)

您不能在同一元素中使用layout_marginlayout_marginRight。在这种情况下,只应用layout_marign。如果您只需要一方的不同保证金,则必须添加所有marginLeftmarginRightmarginTopmarginBottom

答案 1 :(得分:0)

旁注:我建议将android:layout_marginStart用于从右到左的语言。