Search code examples
androidandroid-layoutandroid-11

Android Layout : Height of Linear layout not enough


I am trying to design a layout in android which looks like following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linear"
    android:layout_height="match_parent"

        android:layout_width="match_parent" >



    <LinearLayout

        android:id="@+id/LinearLayout_bt"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:background="@drawable/sec_bluetooth_listview_background"


        android:paddingTop="@*android:dimen/tw_preference_item_padding_top"

        android:paddingBottom="@*android:dimen/tw_preference_item_padding_bottom"

        android:orientation="vertical" >



        <TextView

            android:id="@+id/main_text"
            android:textAppearance="?android:attr/textAppearanceListItem"
            android:textColor="?android:attr/textColorPrimary"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:gravity="center"

            android:singleLine="false"

            android:text="@string/sec_bluetooth_no_devices_found"

            android:ellipsize="none" />



        <TextView

            android:id="@+id/secondary_text"

            style="@style/BluetoothNoItemHelpText"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:gravity="start"

            android:singleLine="false"

            android:lineSpacingExtra="4sp"

            android:ellipsize="none" />



    </LinearLayout>



</LinearLayout>

But the problem is that it is not showing top padding but only bottom padding is working i.e. textview is showing in layout without top padding . I guess there is some problem in height of linear layout but I have set it to wrap-content. Is there any problem in my layout?


Solution

  • Try change your padding values for explicite dp. I changed it in your code and it works fine for me.

    <LinearLayout
            android:id="@+id/LinearLayout_bt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/textLight"
            android:paddingTop="30dp"
            android:paddingBottom="30dp"
            android:orientation="vertical">
    

    with top padding

    with top padding

    and without

    enter image description here