1

レイアウトの背景を半透明の色に設定し、上に境界線 (透明ではない) を設定したいと考えています。私はこれを達成しようとしました。現在、ドローアブル ファイルは次のようになっています。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FF0000FF" />
        </shape>
    </item>
    <item android:top="5dp">
        <shape>
            <solid android:color="#7F000000" />
        </shape>
    </item>
</layer-list>

しかし、この xml では、半透明の形状が非透明の形状になるため、結果として半透明ではありません。私が望む背景を手に入れるのを手伝ってくれませんか?前もって感謝します。

4

2 に答える 2

0

これが1つの簡単な解決策です。

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

    <item android:left="-5dp" android:bottom="-5dp" android:right="-5dp">
        <shape android:shape="rectangle">
            <stroke android:width="5dp" android:color="@color/borderColor" />
            <solid android:color="@color/backgroundColor" />
        </shape>
    </item>

</layer-list>
于 2015-08-26T10:13:19.693 に答える
0

Web を検索して適切な解決策を見つけようとした後、最終的にチャットのメンバーから回答を得ました。解決策はlayout、最初のものの上にもう 1 つ作成し、たとえば の高さ10dpと の幅を与えることですmatch_parent


これが実際の例です:

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/MainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_bg"
    android:orientation="vertical"
    android:padding="5dp"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/Box"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/Border"
            android:layout_width="match_parent"
            android:layout_height="10dp"
            android:layout_weight="0.64"
            android:background="@drawable/border"
            android:orientation="vertical"
            tools:ignore="InefficientWeight" >

        </LinearLayout>

        <TextView
            android:id="@+id/Content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.64"
            android:padding="5dp"
            android:text="@string/example"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/white" />
    </LinearLayout>

</LinearLayout>

main_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="5dp">
        <shape>
            <solid android:color="#FF990000" />
        </shape>
    </item>
</layer-list>

background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="5dp">
        <shape>
            <solid android:color="#55000000" />
        </shape>
    </item>
</layer-list>

ボーダー.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="5dp">
        <shape>
            <solid android:color="#FFFF0000" />
        </shape>
    </item>
</layer-list>

文字列.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Transparent Views</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="example">Content &#8230;</string>
    <color name="white">#FFFFFFFF</color>

</resources>

他の誰かにも役立つことを願っています。

于 2013-06-22T13:23:46.197 に答える