Dialog Layout doesn't show as it should
I use an XML file to define a Dialog that is shown to the user. I'd like to be able to scroll TextViews and EditTexts but show OK and Cancel buttons at all the times. I'm not managing to do that. Here's my Layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearL开发者_JS百科ayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<!-- Group Name -->
<TextView android:id="@+id/group_name_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/group_name_view_text"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/group_name_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Group Description -->
<TextView android:id="@+id/group_description_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:text="@string/group_description_view_text"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/group_description_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Access security -->
<TextView android:id="@+id/access_security_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:text="@string/access_security_view_text"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner android:id="@+id/access_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:gravity="fill_horizontal"
android:drawSelectorOnTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Communications security -->
<TextView android:id="@+id/communcations_security_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:text="@string/communcations_security_view_text"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner android:id="@+id/communications_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:gravity="fill_horizontal"
android:drawSelectorOnTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- User -->
<TextView android:id="@+id/username_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:text="@string/username_view_text"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/username_edit"
android:enabled="false"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Password -->
<TextView android:id="@+id/password_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:text="@string/password_view_text"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/password_edit"
android:enabled="false"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:password="true" android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/ok_text"
android:layout_weight="1" android:id="@+id/group_creator_ok_button">
</Button>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/cancel_text"
android:layout_weight="1"
android:id="@+id/group_creator_cancel_button">
</Button>
</LinearLayout>
</LinearLayout>
I've extended Dialog class so when onCreate is called I call
setContentView(R.layout.my_layout_file);
It is just showing me the ScrollView, but not the layout with the buttons... So I'm not even able to push the buttons.
just changed your ScrollView height like this
<ScrollView
android:layout_width="fill_parent"
android:layout_height="380dp">
and there is no need to write
xmlns:android="http://schemas.android.com/apk/res/android"
on every tag it needs only on first tag
Your scrollview uses wrap-content, so if the content is bigger than the screen, naturally your buttons won't show.
Try using android:layout_weight to assign 'importance' to your layout elements.
An alternative you can look at is to use the <merge>
-tag.
Then you can do something like this:
<merge>
<ScrollView android:layout_height="fill_parent" ... >
...
</ScrollView>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center|bottom" ...>
<Button></Button>....
<LinearLayout>
</merge>
You haven't specified the orientation for the inner LinearLayout. Can you please check with that?
If that doesn't work out, try using with the hierarchyviewer.
精彩评论