Android的RelativeLayout的自定义对话框问题 [英] Android Relativelayout Custom Dialog Problems
本文介绍了Android的RelativeLayout的自定义对话框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些帮助我的RelativeLayout的。我的关闭按钮不能可以看出,当我启动我的自定义对话框。当我将ScollView高度设置为围绕200dp现在只能看到。我不希望手动设置的高度。有没有办法来完成它?也许采用了android:weightSum?请告诉我它是怎么做的。谢谢
OnMenuItemClickListener mAboutButtonClickListener =新OnMenuItemClickListener(){ @覆盖
公共布尔onMenuItemClick(菜单项项){ 最后对话的对话=新的对话框(MainPageActivity.this);
dialog.setContentView(R.layout.about_us);
dialog.setTitle(关于我们);
dialog.setCancelable(真); TextView的文本=(TextView的)dialog.findViewById(R.id.TextView01); 尝试{
资源解析度= getResources();
InputStream的in_s = res.openRawResource(R.raw.disclaimer); 字节[] B =新的字节[in_s.available()];
in_s.read(二);
text.setText(新的String(B)); }赶上(例外五){
// e.printStackTrace();
text.setText(错误:无法显示帮助。);
}
//设置按钮
Button按钮=(按钮)dialog.findViewById(R.id.Button01);
button.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){ dialog.dismiss();
}
});
dialog.show();
返回false;
}
};
我的XML
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
> <滚动型机器人:ID =@ + ID / ScrollView01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:滚动条=垂直
机器人:scrollbarAlwaysDrawVerticalTrack =真正的> < TextView的机器人:ID =@ + ID / TextView01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/> < /滚动型> <按钮机器人:ID =@ + ID / Button01
机器人:layout_below =@ + ID / ScrollView01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:文字=关闭
机器人:layout_alignParentBottom =真/>
< / RelativeLayout的>
解决方案
您可以使用这样的事情。
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /根
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直><滚动型
机器人:layout_width =match_parent
机器人:layout_height =0dip
机器人:layout_weight =1> < TextView的机器人:ID =@ + ID / TextView01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/> < /滚动型> <按钮机器人:ID =@ + ID / Button01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=关闭/> < / LinearLayout中>
I need some help with my relativelayout. My "Close" button cant be seen when i launch my custom dialog. It can only be seen when i set my ScollView Height to around "200dp" . I do not want to manually set the height. Is there a way to accomplish it? Maybe using android:weightSum? Please show me how it is done. Thanks
OnMenuItemClickListener mAboutButtonClickListener = new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
final Dialog dialog = new Dialog(MainPageActivity.this);
dialog.setContentView(R.layout.about_us);
dialog.setTitle("About Us");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
try {
Resources res = getResources();
InputStream in_s = res.openRawResource(R.raw.disclaimer);
byte[] b = new byte[in_s.available()];
in_s.read(b);
text.setText(new String(b));
} catch (Exception e) {
// e.printStackTrace();
text.setText("Error: can't show help.");
}
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
return false;
}
};
My xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
<Button android:id="@+id/Button01"
android:layout_below="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Close"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
解决方案
You can use something like this.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close" />
</LinearLayout>
这篇关于Android的RelativeLayout的自定义对话框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文