2

現在、次のレイアウトがあります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/editorRootView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <RelativeLayout android:id="RL1"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1">
        <!-- LinearLayout needed so we have an border outside of the EditorView -->
        <LinearLayout android:id="LL1"
            android:background="@drawable/border"
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <xenolupus.EditorView
                android:id="@+id/editorView"
                android:layout_width="300dip"
                android:layout_height="216dip" />
        </LinearLayout>
    </RelativeLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/otherImage"
            android:layout_width="150dip"
            android:layout_height="60dip"
            android:text="@string/cardEditor_OtherImageButtonText" />
        <Button
            android:id="@+id/next"
            android:layout_width="150dip"
            android:layout_height="60dip"
            android:text="@string/cardEditor_NextButtonText" />
    </LinearLayout>
</LinearLayout>

そして使用された @drawable/border:

<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid 
        android:color="#FFFFFF" />
    <stroke 
        android:width="10dip" 
        android:color="#FF0099CA" />
    <padding 
        android:left="10dip" 
        android:top="10dip" 
        android:right="10dip"
        android:bottom="10dip" />
    <corners 
        android:radius="5dip" />
</shape>

ただし、Eclipse は、RelativeLayout RL1 の LinearLayout LL1 は役に立たないため、削除する必要があることを警告します (! が付いた黄色の三角形)。

この LinearLayout レイアウトまたはその RelativeLayout 親は役に立ちません。背景属性を他のビューに転送します。

EditorView を中央に配置するには RelativeLayout が必要なので、LinearLayout LL1 を削除して、LinearLayout LL1 の Android:background を EditorView に追加してみました。ただし、これを行うと、EditorView のコンテンツの背後に境界線が表示されなくなります。

EditorView の外に境界線を追加する別の方法はありますか、それとも警告を無視する必要がありますか?

ご挨拶ゼノ・ルプス

4

2 に答える 2

1
    yes it's right, put the background inside your <xenolupus.EditorView 
        like this    
<xenolupus.EditorView
                    android:background="@drawable/border"
                    android:padding="10dp"
                    android:id="@+id/editorView"
                    android:layout_width="300dip"
                    android:layout_height="216dip" />

    and then  add gravity to it parent the RL1 layout  

    > android:gravity="center"
于 2012-08-14T13:08:33.400 に答える
0

ビューはデフォルトで背景を描画できます。正しく開発した場合EditorViewは、バックグラウンドとパディングを XML で直接設定できます。

<xenolupus.EditorView
    android:id="@+id/editorView"
    android:layout_width="300dip"
    android:layout_height="216dip"
    android:background="@drawable/border"
    android:padding="10dp" />

「正しく開発された」とは、ビューがパディングを使用して高さ(またはメソッド)の幅を計算することを意味onMeasureonSizeChangedます。つまり、サイズの計算中にメソッドを使用しました。getPadding*()

ノート

電話することを忘れないでくださいsuper.onDraw()

于 2012-08-14T13:17:46.113 に答える