2012-07-20 85 views
1

我具有以下佈置:機器人:相對佈局寬度WRAP_CONTENT

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" > 

    <ImageView 
     android:id="@+id/personal_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:src="@drawable/dom_logo_new" /> 

    <ImageView 
     android:id="@+id/round_corner_top_left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/corner_white_left_top" /> 

    <ImageView 
     android:id="@+id/round_corner_top_right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/corner_white_right_top" /> 

    <ImageView 
     android:id="@+id/round_corner_bottom_left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/corner_white_left_bottom" /> 

    <ImageView 
     android:id="@+id/round_corner_bottom_right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/corner_white_right_bottom" /> 

</RelativeLayout> 

有1幅主圖像(personal_image)和4個個小圖像。

我需要在屏幕的中心水平顯示主圖像(personal_image),每個角落有4個圖像(左上角,右上角,左下角,右下角)。但RelativeLayout具有所有屏幕的寬度和高度。

我如何可以設置widthRelativeLayout相同width和personal_image的heightheight

回答

0

我建議你使用9-patch而不是角落圖像,這是解決此類問題的Android方法。

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" > 

    <ImageView 
     android:id="@+id/personal_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/round_corner_top_left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/round_corner_top_right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/round_corner_bottom_left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/round_corner_bottom_right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/round_corner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
</LinearLayout> 

由於您正在使用包裝內容,您不必擔心不同的屏幕大小,它將自行管理。

+0

它不工作..小圖像設置相對佈局最大寬度和高度 – yital9 2012-07-20 12:53:46