I am having trouble creating a layout for a dialog I want to display a dialog with a scrollview but with buttons always showing at the bottom but when the scrollview gets too big it pushes the buttons at the bottom off the screen.
I can get the desired effect if i align the buttons at the bottom of the parent to true but then if the scrollview has very little content in it there will be a big dialog with a lot of empty space.
here is what I currently have
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/staCalCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="30dp"
android:text="Company Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ff2525"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/staCalStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Start:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ff2525" />
<TextView
android:id="@+id/staCalStartDisp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Start Time"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp" >
<TextView
android:id="@+id/staCalEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="End:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ff2525" />
<TextView
android:id="@+id/staCalEndDisp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="End Time"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="@+id/staCalSubDisp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ff2525" />
<TextView
android:id="@+id/staCalDesc"
android:layout_width="285dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="15dp"
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal"
android:layout_below="@+id/scrollView1">
<ImageButton
android:id="@+id/calIconSync"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:background="@drawable/calendar_plus" />
<ImageButton
android:id="@+id/btnStaCalClose"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="@drawable/closepopup" />
</RelativeLayout>
trying to get it to display correctly in both landscape and portrait mode but when one works the other does not.
any suggestions on how to go about doing this?
In these cases I just create some other invisible dummy buttons below and align these in such a way that my “real” buttons are positioned correctly.
If the dummy buttons get pushed off the screen that’s fine, the real buttons are above them.
If there is little stuff on the screen the dummy buttons are at the bottom and the “real” buttons are somewhere in the middle.
Make the “invisible” buttons with width = “1dp” and height as much as you need. But leave them visible in the ANdroid sense
EDIT:
you could create a relativeview that aligns its bottom to the bottom of your list view and give it a maxHeight. align your buttons below this relative view. When the listview is small your buttons will be positioned right below it, if your listview is long the relative view exceeds the maxHeight and ensures that it is still on screen so your buttons will be right below the maxHeight. Make sure that maxHeight of the relativeView leaves enough room on the bottom of the screen for the buttons.
To adjust the maxHeight so it leaves enough room for the buttons on any screen size you may use this to get the screensize of the device and adjust the maxHight accordingly to the screenHeight:
Hope that helps also in your case…