Baros
Baros

Reputation: 21

dynamic layout with two buttons problem

how can I set my buttons in a linearLayout dynamically? So I want that all android mobiles with different display sizes can use my app.

Code

<LinearLayout android:id="@+id/linear_layout_main2" android:layout_width="fill_parent" 
android:layout_height="wrap_content" android:orientation="horizontal">

<Button android:id="@+id/bt1" android:text="GO"   
style="@style/button_font" android:clickable="false"     
android:background="@drawable/box1" 
android:layout_marginLeft="6px" />

<Button android:id="@+id/bt2" android:text="ON"   
style="@style/button_font" android:clickable="false"     
android:background="@drawable/box1" 
android:layout_marginLeft="6px" />

</LinearLayout> 

Style-Code

<style name="button_font" parent="@android:style/TextAppearance.Medium">
    <item name="android:layout_width">44px</item>
    <item name="android:layout_height">39px</item>
    <item name="android:textColor">#ffffffff</item>
    <item name="android:textSize">18px</item>
    <item name="android:layout_gravity">center_vertical</item>
</style>

Upvotes: 0

Views: 211

Answers (1)

droid kid
droid kid

Reputation: 7609

You can use android:layout_weight = "1" for two button, then it take same screen ratio.

Means 1:1 ratio is put for the two buttons. So it works in all screen sizes.

Upvotes: 2

Related Questions