2014-01-15 77 views
0

我有以下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文本已消失的地方。主要的问题是,右侧的三个TextViews应该放在布局内部,而不是右侧。我已经尝试了layout_marginRight的各种值,但各​​种值似乎没有影响。我认为有些东西会压倒或压制边际价值,但我不明白它可能是什么。

+0

如果你想发布作为答案,我会检查它。这是一个不愉快的惊喜,因为我希望为其他三方设定默认值,但我想你不能拥有你想要的一切。 –

+0

如你所愿,我移动回答:) – Gooziec

回答

0

您不能在同一元素中使用layout_marginlayout_marginRight。在这种情况下,只会应用layout_marign。如果你想为只有一面不同的保证金,你必须添加所有marginLeftmarginRightmarginTopmarginBottom