2017-07-07 14 views
-7

私は以下のイメージのようなレイアウトをデザインしたいと思っています。どのように私はアンドロイドスタジオで透明な背景をすることができますか?

リニアレイアウトアルファを透明にすると、その中のすべてのアイコンも透明になり、完全に正常になります。しかし、私はちょうど透明な背景がすべてのアイテムではない方法をしたい!

私はこのような透明なレイアウトたい:

enter image description here

を私のレイアウトは次のように示しています。ここ

enter image description here

は私のコードです:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="100dp" 
    android:background="@color/colorPrimary" 
    android:orientation="vertical" 
    android:alpha="0.5" 
    > 



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="1" 
     > 

     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333" 
      android:padding="10dp" 
      > 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333" 
      android:padding="10dp"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333" 
      android:padding="10dp"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
    </LinearLayout> 



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
    </LinearLayout> 

</LinearLayout> 
+1

透明なレイアウトでバックグラウンドを作成し、透明部分であなたのアイコンを設定することができます。あなたの結果はあなたを幸せにするでしょう –

+0

私はそれが私がやったことだと思います!自分のコードでどのように修正できるのか教えていただけますか? tnx – Saeid

+1

LinearLayoutの上に#FF000000というように背景に透明な色を付けてください。これにより、レイアウトウィジェットがalphaプロパティの影響を受けないようになります。 –

答えて

2

あなたはあなたがいればこのようにしてみることができますあなたが望むものであればアルファ値(55)を変更することができます#55000000として与えられた色のアルファ透明な調整を調整するNT。 #55FFFFFF

<?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:background="@color/colorPrimary" 
       android:orientation="vertical" 
    > 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="100dp" 
     android:background="#55000000" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="3" 
      > 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 
     </LinearLayout> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="3" 
      > 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

tnxうまく動作します:) – Saeid

関連する問題