【发布时间】:2019-01-18 20:21:30
【问题描述】:
我正在尝试在对话框片段(实际上是 SherlockDialogFragment)中使用 viewpager。每个页面都包含一个带有左侧可绘制对象的文本视图。我面临的问题是对话框大小是“错误的”。宽度太小,高度太大(它从上到下延伸)。对于宽度,我已经“解决”了这个问题,强制其最小宽度为屏幕宽度的 70%(通过代码,在对话框片段的 onCreateView() 方法中)。至于身高,我不知道如何解决。 下面有个按钮,但是看不到:
viewpager 正在工作(我可以滑动我设置的三个页面)。这是对话框片段布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dlg_bkg"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="TITLE"
android:textStyle="bold"
android:maxLines="1"
android:drawableLeft="@drawable/icon"
android:drawablePadding="8dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<View
android:layout_width="fill_parent"
android:layout_height="2px"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/lineseparator"
android:visibility="visible" />
<android.support.v4.view.ViewPager
android:id="@+id/welcome_dlg_pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</android.support.v4.view.ViewPager>
<View
android:layout_width="fill_parent"
android:layout_height="2px"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/lineseparator"
android:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="?selectableItemBackground"
android:minHeight="40dp"
android:text="Close"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
这是示例页面布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/welcome_dlg_page1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Page 1 - ekrjgwoirhfwiorht2iu3hr2984hr893rhg3hff2jif283hr29837rh283eh23r23r2r23rwrgioehrg803"
android:drawableLeft="@drawable/img1"
android:drawablePadding="8dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
为什么对话框高度太大了?我该如何解决?
【问题讨论】:
-
这是由于 android:background="@drawable/dlg_bkg"。尝试删除它并再次检查。
-
它是一个小的 Ninepatch png。不可能。
标签: android android-layout android-fragments