Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

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?

question from:https://stackoverflow.com/questions/65950244/android-layout-height-of-linear-layout-not-enough

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...