我希望listview-fragment底部的OK / Cancel按钮接受/取消。我认为Fragments是要走的路(甚至应该支持动画)。
但我无法让它工作!它只显示第一个片段(代码中的fragmentPlaceholder)
按钮的xml是我从这篇文章中接受的答案:
How to create standard Borderless buttons (like in the design guidline mentioned)?
代码在C#中,但问题在Java中应该是相同的。片段的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="48dp"
android:layout_alignParentBottom="true">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="?android:attr/dividerVertical"
android:layout_alignParentTop="true"/>
<View
android:id="@+id/ViewColorPickerHelper"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="?android:attr/dividerVertical"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="Cancel"
android:layout_alignParentBottom="true"/>
<Button
android:id="@+id/BtnColorPickerOk"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="?android:attr/selectableItemBackground"
android:text="Ok"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/ViewColorPickerHelper"/>
</RelativeLayout>
活动的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/fragmentPlaceholder" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/addEventReportButtonPlaceholder"
android:layout_weight="10"
android:layout_gravity="bottom" />
</LinearLayout>
<ProgressBar
android:id="@+id/addEventReportProgressBar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
包含片段的代码:
var newFragment = new BottomButtonsFragment ();
FragmentTransaction ft = FragmentManager.BeginTransaction ();
ft.Add (Resource.Id.addEventReportButtonPlaceholder, newFragment).Commit ();
BottomButtonsFragment的位置是:
public class BottomButtonsFragment : Fragment
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.Inflate (Resource.Layout.BottomButtonsFragment, container, false);
return v;
}
}
答案 0 :(得分:0)
将最顶层的LinearLayout的android:layout_weight设置为远远超过底部的那个解决了问题!