有谁知道我如何设置自定义对话框的边距?我问,因为我有一个自定义对话框但是在显示时它会延伸以填充父对象,即使我在布局参数上明确设置了WRAP_CONTENT.
基本上,对话框包含一个listview,其元素必须向下滚动,当元素为1时,它不会拉伸,但是当添加更多项时,对话框占据整个屏幕.
有什么建议?我尝试了所有可能的解决方案组合而没有取得满意的结果
编辑:添加了对话框布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="50dip"
android:orientation="vertical"
android:layout_gravity="top|center">
<FrameLayout android:layout_width="fill_parent" android:layout_margin="5dip" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="20sp" android:textColor="@color/black"/>
<Button android:layout_height="32dip" android:layout_width="32dip"
android:id="@+id/guide_dialog_cross_button"
android:background="@drawable/button_cross_white"/>
</FrameLayout>
<ListView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:fadingEdge="none"
android:layout_margin="5dip"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="5dip" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我似乎无法控制对话框的宽度.我有一个像这样简单的布局
<?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>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,对话框只有足够宽的文本输入字段大约11个字符宽.如何使对话框宽度填满屏幕?
我需要对话框来填充屏幕,除了顶部和底部的一些空间.我正在寻找一个解决方案,但找不到一个可能是因为我正在宣布它onClickListener
.有人可以给一个解决方案吗?
活动代码:
sort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder sort = new AlertDialog.Builder(HomeScreen.this);
// Get the layout inflater
LayoutInflater inflater = HomeScreen.this.getLayoutInflater();
View sortView = inflater.inflate(R.layout.sort_layout, null);
sort.setView(sortView);
sort.create().show();
}
});
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="50dp"
android:layout_marginTop="50dp"
android:background="@color/white"
android:orientation="vertical" android:layout_gravity="center">
+ some more stuff here I dont think it's relevant
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有我能找到的东西(在stackoverflow和网上),但我不知道怎么办不能将我的对话框设置为全屏.它有一个带有textview的scrollview,当textview中的文本不多时,scrollview不是全屏.即使没有多少文字可见,我怎么能强制它全屏?
我创建这样的对话框:
final TextView box;
final Dialog info = new Dialog(cx);
final ScrollView scroll;
info.setContentView(R.layout.dialoginfo);
info.setTitle("Info");
info.setCancelable(true);
info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
scroll = ((ScrollView) info.findViewById(R.id.scrollviewinfo));
scroll.setPersistentDrawingCache(ScrollView.PERSISTENT_NO_CACHE);
scroll.setScrollbarFadingEnabled(false);
box = (TextView) info.findViewById(R.id.infotext);
box.setText(text);
info.show();
Run Code Online (Sandbox Code Playgroud)
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/infolayout"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageView01"
android:layout_weight="1.0"
android:id="@+id/scrollviewinfo">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/infolayout2">
<TextView android:layout_margin="5dip" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/infotext"
android:textSize="8sp"
android:text=""/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我创建了一个自定义对话框,我通过RelativeLayout动态地将视图放入其中.每次显示对话框时,它都会显示我的所有子视图,但它顶部有一些我无法解释的空间.我假设这是为对话框的"标题"保留(我不会有).有没有办法删除该空间并让我的自定义对话框只包装我正在放入的内容?
这是布局的xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/handlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我试过让相对布局成为父节点,结果相同.
这是自定义对话框的.java.
public class HandResults extends Dialog implements DialogInterface {
HandResults hr;
Timer myTimer;
RelativeLayout handrl;
// constructor sets the layout view to handresult layout
public HandResults(Context context) {
super(context);
setContentView(R.layout.handresults);
hr = this;
}
// create a timer to remove the dialog after 3 seconds
public void showHands(){
this.show();
myTimer = null;
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
hr.cancel();
}
}, …
Run Code Online (Sandbox Code Playgroud) 我有一个带有对话框主题的Activity.
<activity
android:name=".MyActivity"
android:theme="@android:style/Theme.Dialog" />
Run Code Online (Sandbox Code Playgroud)
该Activity使用以下xml布局:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_article_frame_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<WebView
android:id="@+id/activity_article_web_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/activity_article_close_button"
android:layout_width="25dip"
android:layout_height="26dip"
android:layout_marginTop="5dip"
android:layout_marginRight="5dip"
android:layout_gravity="right|top"
android:background="@drawable/close_button" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
WebView的内容将从SD卡上的存储文件加载(作为意图数据提供的内容).这发生在onCreate()中:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article);
// Handle to the WebView
mWebView = (WebView) findViewById(R.id.activity_article_web_view);
initWebView();
mWebView.loadDataWithBaseURL(null, myHtmlContent, "text/html", "utf-8", null);
// Handle to the close button
mCloseButton = (Button) findViewById(R.id.activity_article_close_button);
mCloseButton.setOnClickListener(this);
}
Run Code Online (Sandbox Code Playgroud)
项目详情:minSDK:7(2.1)
我的问题是,WebView和/或FrameLayout没有fill_parent.活动的高度与按钮的高度完全相同.我几乎无法阅读我页面的第一行.我的问题只发生在蜂窝3.x上.在下面(<= 2.3),活动填充了父母,我看到了完整的网站.
我试图动态创建WebView.我试图在onCreate()中设置LayoutParams.没有改变.我也尝试在FrameLayout和WebView上调用invalidate(),但结果是一样的......
android webview invalidation fill-parent android-framelayout
android ×6
dialog ×3
fill-parent ×1
fullscreen ×1
invalidation ×1
java ×1
scrollview ×1
textview ×1
webview ×1
width ×1