Reputation: 5506
I'm trying to make a popup with a Dialog with a fixed height, but I can't manage to get it working.
This is my code to build the dialog:
Builder dialogBuilder = new AlertDialog.Builder(this);
ScrollView scvUsersToInvite = (ScrollView) this.mInflater.inflate(R.layout.dialog_users_to_invite, null);
LinearLayout usersToInvite = (LinearLayout) scvUsersToInvite.findViewById(R.id.containerUsersToInvite);
//I add several layouts to the container.
for (int i=0; i<25;i++){
RelativeLayout usuariPerInvitar = (RelativeLayout)this.mInflater.inflate(R.layout.entrada_user_invitar, usersToInvite, false);
TextView tvNomUser = (TextView)usuariPerInvitar.findViewById(R.id.textView1);
tvNomUser.setText("TextView number "+i);
usersToInvite.addView(usuariPerInvitar);
}
dialogBuilder.setView(scvUsersToInvite);
This is working correctly, its filling the layout with 25 times the layout entrada_user_invitar
So those are the XML layouts:
dialog_users_to_invite.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/containerUsersToInvite"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:layout_marginLeft="15dp">
</LinearLayout>
As you can see, height is set to 50dp, but anyways nothing happens.
This is what I inflate several times:
entrada_users_invitar.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" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:text="TextView" />
As you can see in the picture, obviously the dialog is not 50dp height...
How should I write the XML layout to limit the height?
Upvotes: 3
Views: 1171
Reputation: 5506
Ok. Solved it.
I've added a parent layout on dialog_users_to_invite.xml
Now it is:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="100dp" >
<LinearLayout
android:id="@+id/containerUsersToInvite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:layout_marginLeft="15dp">
</LinearLayout>
</ScrollView>
Working perfectly. Everything on wrap_content except the ScrollView, which is 100dp.
Upvotes: 3