0

In my app I have a view with a menu in this way... but I want adapt these 4 buttons for all type of screen, that is I want that these buttons have a dynamic size... do you have any suggestions? thanksenter image description here

this is my current code...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.game.SplashActivity" >

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/back_menu" 
    android:scaleType="centerCrop"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
     >



        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:src="@drawable/bt_1_player"
            android:layout_weight="1"
             />




        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:src="@drawable/bt_2_player" 
            android:layout_weight="1"/>


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:src="@drawable/challenge_bt" 
            android:layout_weight="1"/>


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:src="@drawable/special_bt" 
            android:layout_weight="1"/>

</LinearLayout>

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
  • What does your XML look like so far? – Flexicoder Nov 11 '14 at 09:51
  • 1
    LinearLayout with weight property. – Pr38y Nov 11 '14 at 09:51
  • I edit my question with my code...that doesn't work... – cyclingIsBetter Nov 11 '14 at 09:53
  • 1
    Pr38y is right, use a `LinearLayout` for these buttons. If you want e.g. their height to adjust, set the height of each button to 0dp and give the weight 1. Seems like you are using way to many wrapper layouts, just use one and put the `ImageViews` in there. You don't really the the weight-sum for the parent layout either, just give each button the weight 1. – Blacklight Nov 11 '14 at 09:54
  • ok it seems that it works fine... only one thing... in 7" (mdpi) and 10.1"(mdpi) these buttons remains small... why? I edit my new code... – cyclingIsBetter Nov 11 '14 at 10:09

1 Answers1

2

use below code.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back_menu"
android:orientation="vertical"
tools:context="com.example.game.SplashActivity" >


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:src="@drawable/bt_1_player"
        android:layout_weight="1"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:src="@drawable/bt_2_player"
        android:layout_weight="1"/>


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:src="@drawable/challenge_bt"
        android:layout_weight="1"/>


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:src="@drawable/special_bt"
        android:layout_weight="1"/>

</LinearLayout>
Thirumoorthy
  • 589
  • 2
  • 11