I' have a view that contains several textViews an ImageView and a Button . Because on small screen devices (or in landscape mode on big开发者_运维技巧 ones ) not all are visible I use a Scroll as the parent of the whole hierarchy to allow the user to view all the information. The things are suck that the button must be at the buttom of the view . However on big screen device , where it remains enough space at the buttom , the button is put immediatelly below the last textview,and seems to occupy all the remaining space (resulting in an unnactractive view) . Trying to use android:allignParentButtom ="true" not only that it has no effect but it puts the button at top of the screen . Has anyone any ideea how could I accomplish what I described ?
here's the xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<RelativeLayout
android:id="@+id/gps_info_page1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true">
<TextView
android:id="@+id/itsDateTimeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/eStrUnknown">
</TextView>
<RelativeLayout
android:id="@+id/directions"
android:layout_centerHorizontal="true"
android:layout_below="@+id/itsDateTimeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/itsDirectionValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_marginRight="2dip"
android:textSize="20sp">
</TextView>
<TextView
android:id="@+id/itsOrientation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginLeft="2dip"
android:text="@string/eStrUnknown"
android:layout_toRightOf="@+id/itsDirectionValue">
</TextView>
</RelativeLayout>
<ImageView
android:id="@+id/itsImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/compass"
android:layout_below="@+id/directions"
android:layout_centerHorizontal="true">
</ImageView>
<RelativeLayout>
..."TextViews below the above image"
</RelativeLayout>
<RelativeLayout>
..."TextViews below the above"
</RelativeLayout>
<RelativeLayout>
..."TextViews below the above"
</RelativeLayout>
<RelativeLayout>
..."TextViews below the above"
</RelativeLayout>
<RelativeLayout
..."TextViews below the above"
</RelativeLayout>
<LinearLayout
android:id="@+id/div"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="@+id/sunset_layout"
android:background="#F333">
</LinearLayout>
<Button //adding here android:alignParentBottom="true" has described above behavior
android:layout_marginBottom="3dip"
android:layout_marginTop="20dip"
android:id="@+id/done_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/eStrDone"
android:textSize="18sp"
android:layout_below="@+id/div"
android:layout_centerHorizontal="true">
</Button>
</RelativeLayout>
</ScrollView>
What you can do is change sizes depending on the screen programatically.
With this line you get the density of the screen:
scale = getResources().getDisplayMetrics().density;
and this this you get the size:
windowManager = getWindowManager();
display = windowManager.getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
and with this you can get is its on portarit or landscape:
Configuration conf = context.getResources().getConfiguration();
With all this info, you can modify the screen as you like.
Sometimes is necesary to do some calculations because not only density is different but size is different (like nexus one and droid)
Hope this helps.
Daniel
You could put your scrollview inside a linearlayout and set weight of the scrollview as 1
精彩评论