2012-07-04 8 views
7

こんにちは私の相対的なレイアウトのアルファ値を設定しようとしているが、私はどのようにこの助けを解決するためのエラーを取得しています.....相対レイアウトにアルファ値を設定するにはどうすればよいですか?

私はxmlレイアウトで3つのレイアウトを持っていますフッターを使用してヘッダーの3番目のレイアウトを使用してレイアウト。私は、アルファ値を設定する方法を教えてください私は多くの方法をしようとしていますので、まだ私は見当がつかないアルファ値2 &第三のレイアウトを設定したい

XMLコード:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:orientation="vertical" 
    android:background="@drawable/blue"> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="60px" 
     android:orientation="horizontal" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/gradient_black" 
     android:id="@+id/ttest"> 
     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

     /> 

     <TextView 
      android:id="@+id/header_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="6dp" 
      android:layout_toRightOf="@+id/imageView1" 
      android:text="settings" 
      android:textColor="@color/white" 
      android:textSize="20sp" /> 

    </RelativeLayout> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="55px" 

     android:background="@drawable/gradient_black" 
     android:gravity="bottom" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" > 
    <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ssss" 
     /> 

    </RelativeLayout> 

</RelativeLayout> 

コード:

public class DesignActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     int width = getWindowManager().getDefaultDisplay().getWidth(); 
     int height = getWindowManager().getDefaultDisplay().getHeight(); 


     ImageView imgHead = (ImageView)findViewById(R.id.imageView1); 

     ImageView imgbottom = (ImageView)findViewById(R.id.imageView2); 


     imgbottom.setImageResource(R.drawable.back); 
     imgbottom.setLayoutParams(new RelativeLayout.LayoutParams(width/8, height/8)); 


     imgHead.setImageResource(R.drawable.b); 
     imgHead.setLayoutParams(new RelativeLayout.LayoutParams(width/8, height/8)); 
    // RelativeLayout relative = (RelativeLayout)findViewById(R.id.ttest); 

    } 
} 

答えて

20

この

AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F); 
alpha.setDuration(0); // Make animation instant 
alpha.setFillAfter(true); // Tell it to persist after the animation ends 
// And then on your layout 
yourLayout.startAnimation(alpha); 
+0

あなたは私の一日を作った! – gibffe

8

RelativeLayを試してみてくださいout r1; ...
rl.setAlpha(0.5F);これらの場合において

<RelativeLayout 
    android:id="@+id/rl" 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:background="@drawable/bg" 
    android:alpha="0.5"> 
+0

rl.setAlphaはAPI> = 11が必要です – Darpan

+0

これは、レイアウト全体を透明にします。背景画像だけではありません。私はボタンやテキストビューのようないくつかのビュー要素を持っていましたが、それはルートRelativeLayoutに追加したときにこのアルファ値を取っていました。 –

0

Iは、一般的に、同時に色とアルファを設定する傾向があるので、Aはアルファ値であり、Cは、16進形式、カラーである場合、私はちょうどrl.setBackgroundColor(0xAACCCCCC);を使用します。

例:rl.setBackgroundColor(0x88000000);、0.5透明黒色背景。

またはXML:android:background="#88000000"

関連する問題