I would like to create a full screen header for Android. I created the image that is 70 * 480 px (& 9patch). how can I do? I tried using the galaxy tab .. but it does not fill the screen horizontally. This is the code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:foo="http://schemas.android.com/apk/res/aaa.bbb"
android:id="@+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
<ImageView
android:src="@drawable/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
>
</ImageView>
thanks in advance.
You need to set the android:scaleType and optionally android:adjustViewBounds. Play around with these two attributes to get the desired effect.
http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType
Use this code to add your ImageView to the xml file
<shush.android.util.AspectImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/header" />
Add this class:
package shush.android.util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
/**
* @author Sherif elKhatib
*
*/
public class AspectImageView extends View {
public AspectImageView(Context context) {
super(context);
}
public AspectImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AspectImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = width * getBackground().getIntrinsicHeight()
/ getBackground().getIntrinsicWidth();
setMeasuredDimension(width, height);
}
}
try this
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:foo="http://schemas.android.com/apk/res/aaa.bbb"
android:id="@+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
<ImageView
android:src="@drawable/header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
>
</ImageView>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.