我有一个线性布局,我想用XML文件中从右到左填充一个元素。从右向左填充的原因是%的舍入误差,因为我想匹配右侧的布局。从右到左的Android线性布局
一种是单独为:55% - 15% - 15% - 15%
另一种是:49% - 2% - 34% - 15%
所有我想要的是正确的15%的是完全一样的,因为现在它是不一样的(也许1px的或2px的差异)。
我尝试了方向和重力,但没有得到理想的结果。
编辑:
对不起,这里是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:weightSum="100">
<RelativeLayout
android:id="@+id/leftSideDefaultHoldeTitleBar"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="49"
android:background="@android:color/holo_green_dark">
</RelativeLayout>
<RelativeLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@android:color/darker_gray">
</RelativeLayout>
<RelativeLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="34"
android:background="@android:color/black">
</RelativeLayout>
<RelativeLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="15"
android:background="@android:color/blue"
>
</RelativeLayout>
</LinearLayout>
其他布局是一样的只是在重量的其他价值观,我有摊位放在同一持有人,当我切换他们之间在右侧是一个小错误。
这将有助于看到您的布局或代码中添加UI元素。 – Dave
先发布你的'xml'。我们会很高兴地纠正它! –