3

我有一个包含textview和复选框的线性布局。排列布局中的TextView和复选框时出现问题

<LinearLayout style="@style/linearLayoutStyleNoBgColor" > 
    <TextView 
     android:id="@+id/useFollowupDate" 
     style="@style/textFieldStyleType1WithCheckbox" /> 

    <CheckBox 
     android:id="@+id/checkFollowDate" 
     style="@style/checkboxStyleType1"/> 
</LinearLayout> 

而且款式有:

<style name="linearLayoutStyleNoBgColor"> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">fill_parent</item> 
    <item name="android:layout_margin">5dp</item> 
    <item name="android:weightSum">1.0</item> 
</style> 


<style name="textFieldStyleType1WithCheckbox" parent="@style/textFieldStyleType1"> 
    <item name="android:layout_height">match_parent</item> 
    <item name="android:layout_weight">0.30</item> 
    <item name="android:gravity">center_vertical</item> 
</style> 

<style name="checkboxStyleType1"> 
    <item name="android:layout_width">0dp</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_weight">0.70</item> 
    <item name="android:gravity">right|end</item> 
</style> 

我所试图实现的是

TextView    |  checkbox 
(30%percent screen)  |  (to the right) 

但我得到现在是

TextView   | checkbox 
(30%percent screen) | (left aligned) 

我在哪里去了错误?

+0

你尝试添加利润率的控制? – 2013-03-21 11:30:23

回答

0

如果你想对齐它们,那么你可以使用相对布局。让复选框TextView的

<CheckBox 
     android:id="@+id/checkFollowDate" 
     style="@style/checkboxStyleType1" 
android:layout_toRightOf="@id/useFollowupDate" 
/> 
0

我想你应该改变android:gravityandroid:layout_gravitycheckboxStyleType1

0

Styles.xml

<style name="linearLayoutStyleNoBgColor"> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">fill_parent</item> 
    <item name="android:layout_margin">5dp</item> 
    <item name="android:weightSum">1.0</item> 
</style> 

<style name="textFieldStyleType1WithCheckbox"> 
    <item name="android:layout_width">0dip</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_weight">1</item> 
    <item name="android:gravity">center_vertical</item> 
</style> 

<style name="checkboxStyleType1"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:gravity">right|end</item> 
</style> 

activity_main.xml中

<LinearLayout 
    style="@style/linearLayoutStyleNoBgColor" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/useFollowupDate" 
     style="@style/textFieldStyleType1WithCheckbox" 
     android:text="test" 
     android:layout_width="wrap_content" /> 

    <CheckBox 
     android:id="@+id/checkFollowDate" 
     style="@style/checkboxStyleType1" 
     android:gravity="center_vertical" 
     android:text="checkbox" /> 

</LinearLayout> 
+0

这会炒锅!不过,我需要在屏幕上比例为30:70。请检查问题! – Renjith 2013-03-21 11:55:25