I am fairly new at the whole Android thing so I am hoping this is something obvious that I am overlooking since I have not been able to find a solution online yet.
I am creating a view which contains an ImageView and a "bottom bar". The problem I am having is that since the image is larger than the screen and I would prefer to use something similar to "f开发者_运维技巧ill_parent" or "wrap_content". Ideally I would set the ImageView's height to "fill_parent-44px", but I have not found a way to do this in the XML.
Eventually I plan to have the ImageView function with multi-touch zoom, so it is therefore not an option to resize the image for different screen resolutions.
Thanks for any help.
It's easy to do this with a RelativeLayout
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View android:id="@+id/bottombar"
android:background="#FFCC00"
android:layout_height="40dp"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true" />
<ImageView android:id="@+id/image"
android:src="@drawable/someimage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/bottombar"/>
</RelativeLayout>
The important things here are android:layout_alignParentBottom
and android:layout_above
(see RelativeLayout.LayoutParams for all possible layout attributes).
The android:layout_height="fill_parent"
is more or less ignored given the right RelativeLayout
parameters, it just needs to be there to please the Android UI system.
The android:background
is just for highlighting in the UI designer, and the bottombar
View
can be replaced by any other view like, TextView
, LinearLayout
, etc.
精彩评论