看不到 DialogFragment 中长 ListView 底部的按钮
Button at the bottom of a long ListView in a DialogFragment can't be seen
如果 ListView
有很多 children 并且她需要滚动,我看不到 FragmentDialog
末尾的关闭按钮。
在这里你可以看到 Dismiss Button
:
并且在长 ListView
中您看不到底部的 Dismiss Button
:
dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dialog_header_text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_header_text_view_text"
android:textSize="22sp"
android:textColor="@color/opening_words_dialog_header_color"
android:layout_marginBottom="15sp"
android:textStyle="bold"
/>
<ListView
android:id="@+id/dialog_list_view_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_header_text_view_id"
/>
<Button
android:id="@+id/dialog_dismiss_button_id"
android:layout_width="100sp"
android:layout_height="50sp"
android:text="@string/list_view_button_footer_text"
android:layout_below="@+id/dialog_list_view_id"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
CustomDialogFragment.java:
public class CustomDialogFragmentYearsKnownLoveMails extends DialogFragment
{
TextView listViewItemTextView;
ArrayAdapter<String> arrayAdapter;
ListView dialogListView;
String[] items = new String[120];
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.dialog, container,false);
setCancelable(false);
listViewItemTextView = (TextView) rootView.findViewById(R.id.list_view_item_text_view_id);
dialogListView = (ListView) rootView.findViewById(R.id.dialog_list_view_id);
dissmissDialogButton = (Button) rootView.findViewById(R.id.dialog_dismiss_button_id);
for (int i = 0;i < items.length;i++)
{
items[i] = "" + (i + 1);
}
arrayAdapter = new ArrayAdapter<String>(LoveMailsActivity.this, R.layout.list_view_row,R.id.row_text_view_id,items);
dialogListView.setAdapter(arrayAdapter);
dialogListView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Toast.makeText(getActivity(), items[position], Toast.LENGTH_SHORT).show();
loveEmailYearsKnownTextView.setText(items[position]);
}
});
dissmissDialogButton.setOnClickListener(new View.OnClickListener() // Dismiss button click
{
@Override
public void onClick(View v)
{
dismiss();
}
});
return rootView;
}
}
那么它有什么问题呢?
如果您需要更多信息,请询问。
对于 XML 中的列表视图,将属性 layout_below 更改为 layout_above ="@id/dialog_dismiss_button_id"
并从 Button 中删除 layout_below 属性。并将其添加到按钮
android:layout_alignParentBottom="true"
希望这对你有帮助:)
列表视图,受上下约束,是"stretch"从文本视图的底部(即基线)到按钮的顶部。通常我开始编写触及父视图的组件(即对齐父视图 top/bottom),并以中间的视图作为此视图列表结束。
诀窍是像这样扩展文本视图下方和按钮上方的列表:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dialog_header_text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_header_text_view_text"
android:textSize="22sp"
android:textColor="@color/opening_words_dialog_header_color"
android:layout_marginBottom="15sp"
android:textStyle="bold"
/>
<Button
android:id="@+id/dialog_dismiss_button_id"
android:layout_width="100sp"
android:layout_height="50sp"
android:text="@string/list_view_button_footer_text"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
<ListView
android:id="@+id/dialog_list_view_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_header_text_view_id"
android:layout_above="@id/dialog_dismiss_button_id"
/>
</RelativeLayout>
如果 ListView
有很多 children 并且她需要滚动,我看不到 FragmentDialog
末尾的关闭按钮。
在这里你可以看到 Dismiss Button
:
并且在长 ListView
中您看不到底部的 Dismiss Button
:
dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dialog_header_text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_header_text_view_text"
android:textSize="22sp"
android:textColor="@color/opening_words_dialog_header_color"
android:layout_marginBottom="15sp"
android:textStyle="bold"
/>
<ListView
android:id="@+id/dialog_list_view_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_header_text_view_id"
/>
<Button
android:id="@+id/dialog_dismiss_button_id"
android:layout_width="100sp"
android:layout_height="50sp"
android:text="@string/list_view_button_footer_text"
android:layout_below="@+id/dialog_list_view_id"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
CustomDialogFragment.java:
public class CustomDialogFragmentYearsKnownLoveMails extends DialogFragment
{
TextView listViewItemTextView;
ArrayAdapter<String> arrayAdapter;
ListView dialogListView;
String[] items = new String[120];
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.dialog, container,false);
setCancelable(false);
listViewItemTextView = (TextView) rootView.findViewById(R.id.list_view_item_text_view_id);
dialogListView = (ListView) rootView.findViewById(R.id.dialog_list_view_id);
dissmissDialogButton = (Button) rootView.findViewById(R.id.dialog_dismiss_button_id);
for (int i = 0;i < items.length;i++)
{
items[i] = "" + (i + 1);
}
arrayAdapter = new ArrayAdapter<String>(LoveMailsActivity.this, R.layout.list_view_row,R.id.row_text_view_id,items);
dialogListView.setAdapter(arrayAdapter);
dialogListView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Toast.makeText(getActivity(), items[position], Toast.LENGTH_SHORT).show();
loveEmailYearsKnownTextView.setText(items[position]);
}
});
dissmissDialogButton.setOnClickListener(new View.OnClickListener() // Dismiss button click
{
@Override
public void onClick(View v)
{
dismiss();
}
});
return rootView;
}
}
那么它有什么问题呢? 如果您需要更多信息,请询问。
对于 XML 中的列表视图,将属性 layout_below 更改为 layout_above ="@id/dialog_dismiss_button_id"
并从 Button 中删除 layout_below 属性。并将其添加到按钮
android:layout_alignParentBottom="true"
希望这对你有帮助:)
列表视图,受上下约束,是"stretch"从文本视图的底部(即基线)到按钮的顶部。通常我开始编写触及父视图的组件(即对齐父视图 top/bottom),并以中间的视图作为此视图列表结束。
诀窍是像这样扩展文本视图下方和按钮上方的列表:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dialog_header_text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_header_text_view_text"
android:textSize="22sp"
android:textColor="@color/opening_words_dialog_header_color"
android:layout_marginBottom="15sp"
android:textStyle="bold"
/>
<Button
android:id="@+id/dialog_dismiss_button_id"
android:layout_width="100sp"
android:layout_height="50sp"
android:text="@string/list_view_button_footer_text"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
<ListView
android:id="@+id/dialog_list_view_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_header_text_view_id"
android:layout_above="@id/dialog_dismiss_button_id"
/>
</RelativeLayout>