首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android对话框宽度

Android对话框宽度
EN

Stack Overflow用户
提问于 2010-04-14 12:17:12
回答 6查看 80.8K关注 0票数 50

我似乎无法控制对话框的宽度。我有一个简单的布局,像so` `

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:theme="@android:style/Theme.Dialog"> 

    <ScrollView 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout     android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView 
            android:id="@+id/name_prompt_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/name_prompt"
            android:padding="10dip"/>

        <EditText 
            android:id="@+id/name_inp" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:lines="1"
            android:maxLines="1"
            android:maxLength="48"
            android:inputType="text" />

        <TextView 
            android:id="@+id/t1_prompt_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/t1_prompt"
            android:padding="10dip"/>

        <Spinner 
            android:id="@+id/t1_inp" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:lines="1"
            android:maxLines="1"
            android:maxLength="48"
            android:inputType="text"
            android:singleLine="true"
            android:layout_weight="1"
            android:entries= "@array/t1_allowed_values" />

         </LinearLayout>

    </ScrollView>

</LinearLayout>

由于某些原因,该对话框仅够文本输入字段使用大约11个字符的宽度。如何使对话框宽度充满整个屏幕?

EN

回答 6

Stack Overflow用户

发布于 2010-04-21 14:01:51

我也有同样的问题。

我使用下面的代码来制作对话框fill_parent,它工作得很好。

public class SharePost extends Dialog
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.adaptor_contentsharepost);

        LayoutParams params = getWindow().getAttributes();
        params.height = LayoutParams.FILL_PARENT;
        getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
    }
}

布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@+id/dialogWidth"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    contents here

</LinearLayout>
票数 86
EN

Stack Overflow用户

发布于 2012-06-25 07:10:40

我使用的是:

getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
票数 57
EN

Stack Overflow用户

发布于 2013-04-18 14:31:32

在最上面的布局设置最小宽度。

android:minWidth="300dp"

例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="300dp">

<!-- Put remaining contents here -->

</LinearLayout>
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2634850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档