我需要一些有关我的相对布局的帮助。当我启动自定义对话框时,看不到我的“关闭”按钮。只有当我将 ScollView Height 设置为 "200dp" 左右时才能看到它。我不想手动设置高度。有没有办法实现它?也许使用 android:weightSum?请告诉我它是如何完成的。谢谢
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;
}
};
我的 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>