0

サイズの小さい順に 7 つの四角形を描画するために、drawable フォルダーに 7 つの xml ファイルがあります。各 xml ファイルは、imageview のバックグラウンド リソースです。これは、7 つの imageview があることを意味します。

相対的なレイアウトを使用して、サイズが小さい順にそれらを重ねて配置し、最小の長方形が上になるようにしました。

長方形の描画可能な xml ファイルの 1 つのサンプル xml を次に示します。

   <?xml version="1.0" encoding="utf-8"?>
<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">

  <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="90"/>
        <solid
        android:color="#FFFF0000"></solid>
         <stroke android:width="1px" android:color="#cccccc" />

            <padding android:left="50dp"
        android:top="10dp"
        android:right="50dp"
        android:bottom="10dp" />
    <corners android:radius="8dp" />

</shape>

属性「android:layout_above」を使用して長方形のスタックを取得しましたが、長方形は片側に配置されていますが、どちらの側にも配置せず、両側の縮小エッジとして表示したくありません。

基本的に、すべての長方形を中央に配置して、上の長方形の縮小されたエッジが下の長方形の下部に見えるようにしたいのですが、私を助けることができるimageviewの属性が見つかりません。

これは、水平スクロール ビュー内にある私の相対的なレイアウトです:-

 <RelativeLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/desert">

        <ImageView 
            android:id="@+id/camel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"/>

        <ImageView 
            android:id="@+id/puppet"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_alignParentBottom="true"/>


        <ImageView 
            android:id="@+id/sun"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_alignParentTop="true"/>

        <ImageView 
            android:id="@+id/hand"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            android:layout_marginBottom="100dp"
            android:layout_marginTop="150dp"
            android:layout_alignParentTop="true"/>

        <ImageView
            android:id="@+id/stone1"
            android:background="@drawable/stone1"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_alignParentBottom="true"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun"/>

        <ImageView
            android:id="@+id/stone2"
            android:background="@drawable/stone2"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_above="@id/stone1"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun"/>
        <ImageView
            android:id="@+id/stone3"
            android:background="@drawable/stone3"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_above="@id/stone2"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun" />
        <ImageView
            android:id="@+id/stone4"
            android:background="@drawable/stone4"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" 
            android:layout_above="@id/stone3"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun"/>
        <ImageView
            android:id="@+id/stone5"
            android:background="@drawable/stone5"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_above="@id/stone4"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun" />
        <ImageView
            android:id="@+id/stone6"
            android:background="@drawable/stone6"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_above="@id/stone5"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun" />
        <ImageView
            android:id="@+id/stone7"
            android:background="@drawable/stone7"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_above="@id/stone6"
            android:scaleType="center"
            android:layout_toRightOf="@id/sun" />
    </RelativeLayout>
4

3 に答える 3

0

相対的なレイアウトを表示してください。イメージビュー (長方形) に次の値のいずれかを設定します。

 android:layout_centerHorizontal="true"

また

 android:layout_centerInParent="true"
于 2011-08-11T21:11:21.277 に答える
0

android:gravity相対レイアウトで設定することをお勧めします

于 2011-08-11T21:14:20.597 に答える
0

「android:layout_marginLeft」を適切な値に設定することで問題を解決しました。 つまり、最小の長方形が左から最も遠く、最大の長方形が最も近く、隣接する各長方形には上記のパラメーターの 5 dp の差がありました。そして、ピラミッドを取得しました:)

于 2011-08-12T03:02:15.813 に答える