2012-05-17 44 views
0

我想为Android创建一个全屏幕标题。 我创建了70 * 480像素的图像(& 9patch)。 我该怎么办? 我尝试使用银河标签..但它不会水平填充屏幕。 这是代码:标题android 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> 

在此先感谢。

回答

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); 
    } 
} 
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>