我希望我的对话框不像所示的图像那样适合整个屏幕。我该如何制作它不会那么长(高度)。
public class SidemenuInfoDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.sidemenu_info_main, container, true);
return layout;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(new ContextThemeWrapper(getActivity(), R.style.Theme_Window_NoMinWith));
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
}
视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/sidemenu_info_main_relative">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/text1"
android:text="TEST TEXT "/>
</RelativeLayout>
让我知道是否还需要其他东西才能帮助我找到解决问题的正确途径。
答案 0 :(得分:2)
将对话框视图高度和宽度内的textview设为“wrap_content”。赞:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/sidemenu_info_main_relative">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:text="TEST TEXT "/>
</RelativeLayout>
答案 1 :(得分:1)
尝试更改xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/sidemenu_info_main_relative">
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:id="@+id/text1"
android:text="TEST TEXT "/>
</RelativeLayout>
如果这对您不起作用,这是我通常采用的另一种方法:
public class PopUp {
public void poupUP(final Activity activity) {
final Dialog dialog = new Dialog(activity, R.style.dialogwithoutTitle);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//here add the layout
dialog.setContentView(R.layout.pop_up);
// The comments are to change the position of the alert dialogu
// WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
//wmlp.gravity = Gravity.TOP | Gravity.END;
//wmlp.x = 100; //x position
//wmlp.y = 100; //y position
dialog.show();
}
}
然后,无论您希望它显示在何处执行此操作:
PopUp p = new PopUp();
p.popUP();
答案 2 :(得分:0)
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.sidemenu_info_main, container, false);
答案 3 :(得分:0)
试试这个:
alert.getWindow().setLayout(dialogWidth, LayoutParams.WRAP_CONTENT);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(alert.getWindow().getAttributes());
layoutParams.x = xPosition;
layoutParams.y = yPosition;
alert.getWindow().setAttributes(layoutParams);