1

I have a problem with my XML file. I want to have a layout which places 3 buttons on the whole screen. If I use 4 inch device and fixed dp or dip values I can get what I want. But if I use 10 inch tablet the layout looks small. Here is my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical"
android:padding="10dip"
tools:context=".Main" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dip" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="DOBRODOŠLI!"
        android:textSize="25sp" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false" >

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="33"
        android:orientation="vertical" >

        <Button
            android:id="@+id/bCV"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/cv"
            android:textSize="13sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="33"
        android:orientation="vertical" >

        <Button
            android:id="@+id/bApplicationLetter"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/application_letter"
            android:textSize="13sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="33"
        android:orientation="vertical" >

        <Button
            android:id="@+id/bEmail"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:text="@string/email"
            android:textSize="13sp" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false" >

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="33"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/cv"
            android:textSize="13sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="33"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Motivacijsko"
            android:textSize="13sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="33"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/email"
            android:textSize="13sp" />
    </LinearLayout>
</LinearLayout>

This is how I want my layout to look: https://i.stack.imgur.com/WmcZk.png

Thanks in advance! :D

  • When you say the layout looks small, do you mean that the height is small or the width of the display is small or the entire layout. Looking at this, it seems that everything should work fine. – ucsunil Mar 08 '14 at 21:41
  • I tried even with the relative layout, but that didn't work out either... I deleted the XML code... And when I say it is small I think that it does not take the most of the screen (like on the picture). It looks like this: http://i.imgur.com/XANQ8qk.png – user3121092 Mar 08 '14 at 21:44
  • Your root layout is set to wrap_content. Can you set it to match_parent and see what happens? It should occupy your whole screen now. – ucsunil Mar 08 '14 at 21:50
  • I tried this, but than it goes over those 3 TextViews below the buttons... – user3121092 Mar 08 '14 at 21:52
  • I see you have two layouts - my bad. I thought you had one. Set the weight of the top linear layout to be 90 and the weight of the bottom linear layout to 10. Should divide the screen in a 9:1 ratio (change according to your want). – ucsunil Mar 08 '14 at 21:54
  • I tried that too, but then I get this warning: "Nested weights are bad for performance", plus - nothing happens :S And about the warning: http://stackoverflow.com/questions/9430764/why-are-nested-weights-bad-for-performance-alternatives But this does not suit my needs... Just try and copy and paste my code into your eclipse and see what happens... I really tried a lots of things. :S – user3121092 Mar 08 '14 at 22:01

0 Answers0