嗨,我想在操作栏的底部显示自定义弹出式布局。但是我试图将视图定位到另一个视图。
我实际上得到的是:
我试图做到这一点。
//扩大布局
col
//显示操作栏的布局底部
View filterLayout = getLayoutInflater().inflate(R.layout.tooltip_layout, null);
filterPopup = new PopupWindow(this);
/* filterPopup.setWidth(ListPopupWindow.MATCH_PARENT);
filterPopup.setHeight(ListPopupWindow.WRAP_CONTENT);*/
filterPopup.setOutsideTouchable(true);
filterPopup.setContentView(filterLayout);
filterPopup.setBackgroundDrawable(new BitmapDrawable());
filterPopup.setFocusable(true);
//这是我的工具提示布局
int[] location = new int[2];
mActivityMainBinding.appBarMain.contentMain.mainContentLayout.getLocationOnScreen(location);
Point point = new Point();
point.x = location[0];
point.y = location[1];
filterPopup.showAtLocation(mActivityMainBinding.appBarMain.toolbar, Gravity.LEFT | Gravity.TOP, point.x, point.y);
任何人都可以指导我如何实现这一目标吗?我想显示卡片视图布局以与操作栏底部对齐对齐。
答案 0 :(得分:0)
完整指南:)
layout_popup.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="130dp"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/expand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:paddingLeft="10dp"
android:text="@string/company"
android:textAllCaps="true"
android:textColor="#000000" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#00000000"
android:padding="7dp"
android:scaleType="fitCenter"
android:src="@drawable/arr" />
</LinearLayout>
<net.cachapa.expandablelayout.ExpandableLayout
android:id="@+id/expandable_recycler_local"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
app:el_expanded="false">
<android.support.v7.widget.RecyclerView
android:id="@+id/rec_company_list"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:background="@drawable/round_shape_edit_text"
android:nestedScrollingEnabled="false"></android.support.v7.widget.RecyclerView>
</net.cachapa.expandablelayout.ExpandableLayout>
<View
android:layout_width="130dp"
android:layout_height="2dp"
android:layout_marginTop="5dp"
android:background="#12CED5"></View>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="@string/line_number"
android:textAllCaps="true"
android:textColor="#000000" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal"
android:paddingRight="10dp"
android:visibility="gone">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textAllCaps="true"
android:textSize="18dp"
android:textStyle="bold"
ads:buttonTint="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textAllCaps="true"
android:textSize="18dp"
android:textStyle="bold"
ads:buttonTint="#000000" />
</RadioGroup>
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:id="@+id/btn_save"
android:background="@drawable/grd"
android:text="@string/save"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>
然后用Java代码
btnSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupWindow window = new PopupWindow(HomeActivity.this);
window.setFocusable(true);
window.setContentView(view1);
window.showAsDropDown(view);
linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (expandableLayout.isExpanded()) {
expandableLayout.collapse();
} else {
expandableLayout.expand();
}
}
});
}
});