开发者

Rotation Problem

My android application has two imagebut开发者_开发知识库tons side by side of equal lenght. They fill a line. I turn my phone but imagebuttons is not filling the line. Even if the phone rotate How do I displaying correctly? Thanks


Use the weight property of the linear layout. Put both the button in a liner layout, specify layout_width = odp and weight=1 for both the button. The weight elements allows you to specify the ratio of the width each element will take . Here is a sample

<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content"                    
  android:layout_alignParentBottom="true" android:layout_width="fill_parent">
  <Button android:text="Button" android:id="@+id/button1" 
    android:layout_height="wrap_content" android:layout_width="0dp"
    android:layout_weight="1">
  </Button>
  <Button android:text="Button" android:id="@+id/button2"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:layout_width="0dp">
  </Button>
</LinearLayout> 

Edit: the sample is for a button , but you can use it for an image button too


Put both the buttons in TableRow & check after rotation if it works as expected.


Make sure you have width set to "fill_parent" and the weights adjusted correctly if you are using horizontal layout.

You can also, in onCreate, set the width of the image buttons manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜