如何解决Android 布局:线性布局的高度不够
我正在尝试在 android 中设计一个布局,如下所示:
<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>
但问题是它没有显示顶部填充,而只有底部填充在工作,即 textview
显示在没有顶部填充的布局中。我猜线性布局的高度存在一些问题,但我已将其设置为 wrap-content
。我的布局有问题吗?
解决方法
尝试更改显式 dp 的填充值。我在您的代码中对其进行了更改,对我来说效果很好。
<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">
顶部填充
和没有
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。