coh*_*air 2 android listview android-listview android-dialog android-dialogfragment
点击DialogFragment时我会被显示出来TextView.它DialogFragment有自己的XML布局文件,a ListView,a EditText和Button底部.
问题是,当ListView只有少数几个项目时,DialogFragment仍占据屏幕的大部分(即高度远大于应有的高度).
这是我的意思的截图(黑色是ListView一个项目):
正如你所看到的那样,ListView当我希望Dialog它只是它需要的大小时,就会有大量的空白空间.
这是DialogFragentXML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_small"
tools:context="com.cohenadair.anglerslog.fragments.ManageFragment">
<LinearLayout
android:id="@+id/add_item_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/new_item_edit"
android:layout_weight="1"
android:hint="@string/hint_new_item"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_add"
android:id="@+id/add_button"
android:layout_margin="0dp"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/add_item_layout"
android:id="@+id/content_list_view"
android:background="@android:color/black">
</ListView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
而且onCreateView:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_manage_primitive, container, false);
int primitiveId = getArguments().getInt(ARG_PRIMITIVE_ID);
PrimitiveFragmentInfo info = FragmentUtils.primitiveInfo(getActivity(), primitiveId);
if (info != null) {
initViews(view, info);
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
}
return view;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我通过交换解决了它RelativeLayout,并使用LinearLayout与layout_weight性能.
这是新的XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_small"
android:orientation="vertical"
tools:context="com.cohenadair.anglerslog.fragments.ManageFragment">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/content_list_view">
</ListView>
<LinearLayout
android:id="@+id/add_item_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/new_item_edit"
android:layout_weight="1"
android:hint="@string/hint_new_item"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_add"
android:id="@+id/add_button"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2839 次 |
| 最近记录: |