Android 如何在下方文本视图中显示弹出窗口
我希望能够在我的文本视图下显示我的弹出窗口。我已经学习了教程,但仍然无法让它显示在我想要的地方 我希望它显示在键下面(TextView) 我的Xml布局:Android 如何在下方文本视图中显示弹出窗口,android,android-layout,popupwindow,android-popupwindow,Android,Android Layout,Popupwindow,Android Popupwindow,我希望能够在我的文本视图下显示我的弹出窗口。我已经学习了教程,但仍然无法让它显示在我想要的地方 我希望它显示在键下面(TextView) 我的Xml布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_master"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.myview.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="10dp"
android:text="Options" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tagSpinner" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="sampleTxt" />
<EditText
android:id="@+id/tagKey"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Type me.."></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="value" />
<EditText
android:id="@+id/tagval"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Enter value"/>
</LinearLayout>
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="btnclick"
android:id="@+id/aaaa" />
</LinearLayout>
</LinearLayout>
编辑:我也不介意它在屏幕上被切断你如何实际显示你的
弹出窗口
?共享代码@azizbekian@bhandari,编辑:我发现了问题,这是由于弹出窗口的宽度造成的。宽度将尖端向左推,因此将其从TextView中移开。如果我将宽度设置为较小的值,则可以解决问题。请参阅此帖子
Clicking the button in the main screen try the below code:-
Button buttonAction;
final PopupWindow mPopupwindow;
LayoutInflater mInflater = (LayoutInflater) mActivity.getSystemService(mActivity.LAYOUT_INFLATER_SERVICE);
View mView = mInflater.inflate(R.layout.popup_layout,layouttext,false);
mPopupwindow = new PopupWindow(mView, 300, 300, true);
mPopupwindow.showAsDropDown(layouttext,0,5);
buttonAction = (Button) mView.findViewById(R.id.buttonAction);
buttonAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mPopupwindow.dismiss();
}
});