Reputation: 279
Hi I am developing an app which has 11 Buttons. I have created a Relative layout and arranged the buttons how I want them to be. In Android studio I am using a nexus 4 screen as a guide.
Now when I run my app on screens with lower resolution like lets say 320*480 my last butto disappears or rather goes out of the screen. As seen in the below pic.
All my widths and heights are in dip. How do I resolve this?
Upvotes: 0
Views: 895
Reputation: 8939
You should use LinearLayout
with android:weightSum
1.set the android:weightSum of the parent
2.set the android:layout_weight of each child proportionally (e.g. weightSum="6"
, six children: layout_weight="1"
for each)
3. And use Dimension
to give size of Button, check this and this
layout.xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="6">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" />
///////////////
</LinearLayout>
Upvotes: 0
Reputation: 8700
You need to understand that although using dp is the right way to go when designing for android, it doesn't mean that every screen has the same amount of dp exactly.
You can either make your layout a bit smaller for everyone or you could try to put every row of buttons in a horizontal linear layout, giving each button equal android:layout_weight
, that way they will spread out evenly no matter the size of the screen. Use margins to control the spacing between them.
You can solve the vertical problem with weights with the same principal: put every row in a vertical linear layout and give them equal weights.
Upvotes: 1