2014-07-14 23 views
0

我希望你能帮助我,因为这是推动我坚果...RelativeLayout的推压中心查看到右

我有一个简单RelativeLayout有两个子视图,你可以将代码样本中看到。 TextView应该是居中ProgressBar左对齐

在布局编辑器中,这是正确渲染的,但在设备/仿真器上TextView被推到右边,并且ProgressBar也有一个随机偏移量。

你可以忽略文本和按钮颜色不同的事实,我已经检查过这没有什么区别。

<RelativeLayout 
    android:id="@+id/popup_redeem_button" 
    android:layout_margin="@dimen/margin_outer" 
    android:background="@drawable/button_rounded_yellow" 
    android:clickable="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <de.fireflow.milebox.ui.views.TypefaceTextView 
     android:id="@+id/popup_redeem_text" 
     style="@style/ButtonHeadlineMenu_Font" 
     app:richText="true" 
     android:padding="@dimen/margin_normal" 
     android:text="@string/voucher_redeem" 
     android:layout_centerInParent="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

    <ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/progressBarStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:indeterminate="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="@dimen/margin_normal" 
     android:indeterminateBehavior="cycle" 
     android:layout_gravity="center_horizontal"/> 
    </RelativeLayout> 

形状的按钮背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners 
    android:radius="6dp" 
    /> 

    <solid 
    android:color="@color/btn_yellow_pressed" 
    /> 
</shape> 

enter image description here

我不衡量或更改任何布局界限的代码,所以我真的不认为这个问题的。有任何想法吗?

+1

尝试将自定义'TextView'的'layout_width'更改为''match_parent“',并将其'gravity'设置为'center_horizo​​ntal'。 –

+1

谢谢,这真的解决了这个问题。简单但高效:D。如果你添加它作为答案,我会接受它 – McLovin

+0

哦,neato!我会。谢谢! –

回答

1

我建议您尝试更改自定义TextViewlayout_widthmatch_parent,并将gravity设置为center_horizontal。这将拉伸TextView以水平覆盖父级,然后它可以自行将自己的文本居中。由于您在TextView之后列出了ProgressBar,所以z顺序将是正确的,并且ProgressBar将出现在TextView之上。