0

Android用の全画面ヘッダーを作成したいと思います。70 * 480 px (& 9patch) の画像を作成しました。どのようにできるのか?ギャラクシータブを使ってみたのですが、画面いっぱいに横に収まりません。これはコードです:

<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>

前もって感謝します。

4

3 に答える 3

0

これを試して

<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>
于 2012-05-17T13:09:35.717 に答える
0

このコードを使用して、ImageView を xml ファイルに追加します

            <shush.android.util.AspectImageView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/header" />

このクラスを追加します。

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);
    }
}
于 2012-05-17T11:23:29.717 に答える
0

android:scaleType とオプションで android:adjustViewBounds を設定する必要があります。これら 2 つの属性をいじって、目的の効果を得ます。

http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

于 2012-05-17T11:12:19.347 に答える