gpt4 book ai didi

android - 自定义对话框太小

转载 作者:IT老高 更新时间:2023-10-28 23:37:14 25 4
gpt4 key购买 nike

我有一个实现自定义对话框的 android Activity 。应用程序运行正常,但对话框太小,我想显示一个更大的对话框。我该如何实现?这是我的布局 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/view_more_borders">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="4dp"
android:gravity="center_vertical">

<TextView
android:id="@+id/share_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Company Name:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue"
android:typeface="sans" />

<TextView
android:id="@+id/textViewCompanyName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.80"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">

<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Price per share:"

android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />

<TextView
android:id="@+id/textViewprice_pershare"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_alignBaseline="@+id/Yesterday"
android:layout_alignBottom="@+id/Yesterday"
android:layout_marginLeft="38dp"
android:fontFamily="sans-serif"
android:layout_toRightOf="@+id/company"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">

<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Total cost:"

android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />

<TextView
android:id="@+id/textview_totalcost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_alignBaseline="@+id/Yesterday"
android:layout_alignBottom="@+id/Yesterday"
android:layout_marginLeft="38dp"
android:fontFamily="sans-serif"
android:layout_toRightOf="@+id/company"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">

<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Number of shares:"

android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />

<EditText
android:id="@+id/shareNumber"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="number"
android:fontFamily="sans-serif"
android:textSize="12sp"
>

<requestFocus />
</EditText>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">


<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Payment method:"

android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />

<Spinner
android:id="@+id/spinner_paymentmode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />

</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/button_buy_shares"
style="@style/ButtonText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/blue_button"
android:text="Buy" />

这是我的输出。我想增加对话框的宽度和高度。 enter image description here

还有我的 java 文件

public class MyDialogFragment extends DialogFragment {

public MyDialogFragment() {

}

private EditText mEditText;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialogfragment, container);
// mEditText = (EditText) view.findViewById(R.id.txt_your_name);
// getDialog().setTitle("Hello");
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

return view;
}
}

最佳答案

在运行时更改对话框尺寸:

yourDialog.show();
yourDialog.getWindow().setLayout((6 * width)/7, LayoutParams.WRAP_CONTENT);

您可以在两个维度上都这样做,在我的示例中,我只更改了宽度。希望对您有所帮助!

编辑

我忘了说我在哪里取了宽度:

DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;

编辑 2

试试这个代码:

Dialog yourDialog = dialogFragment.getDialog();
yourDialog.getWindow().setLayout((6 * width)/7, (4 * height)/5);

关于android - 自定义对话框太小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19133822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com