2014-02-26 19 views
-1

我的佈局文件是這樣的:Android:自定義可繪製佈局背景。兒童用品不清楚?

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

    <LinearLayout 
     android:layout_width="282dp" 
     android:layout_height="wrap_content" 
     android:layout_x="20dp" 
     android:layout_y="208dp" 
     android:alpha="155" 
     android:orientation="vertical" > 

     <EditText 
      android:id="@+id/txtUserName" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:alpha="155" 
      android:hint="@string/hintUsername" 
      android:padding="2dp" > 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/txtPassword" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:alpha="155" 
      android:hint="@string/hintPassword" 
      android:inputType="textPassword" 
      android:padding="2dp" /> 

     <Button 
      android:id="@+id/butBrowse" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:alpha="255" 
      android:text="@string/but_browse" /> 
    </LinearLayout> 

我設置自定義可繪製佈局編程如下:

ViewGroup layoutView = (ViewGroup) getLayoutInflater().inflate(
       R.layout.login_layout, null); // (ViewGroup) 
     layoutView.setBackground(new CustomDrawable(this) { 
     }); 

private class CustomDrawable extends Drawable { 

    private Context ctx; 
    private Bitmap bitmap; 

    public CustomDrawable(Context ctx) { 
     this.ctx = ctx; 
     init(); 
    } 

    private void init() { 
    //draw dynamic stuff to the 'bitmap' 
    } 

    @Override 
    public void draw(Canvas canvas) { 
     canvas.save(); 
     Paint p = new Paint(); 
     canvas.drawBitmap(this.bitmap,0,0,p); 

     canvas.restore(); 
    } 

    @Override 
    public int getOpacity() { 
     return 15; 
    } 

    @Override 
    public void setAlpha(int alpha) { 

    } 

    @Override 
    public void setColorFilter(ColorFilter cf) { 

    } 

} 

現在我login_layout看起來是這樣的:

enter image description here

從圖中可以看出,我的子元素(edittext,密碼區,按鈕)並不清晰可見樂。

enter image description here

我的問題:

1.How實現像上面我必須到另一個可繪製適用於內 '的LinearLayout'?

2.是否可以更改文本字段,按鈕的alpha級別以便它更清晰可見?

回答

0

您需要更改當前設置爲15的自定義繪圖的不透明度。增加不透明度將使其更加明顯。

@Override 
    public int getOpacity() { 
     return 15; // increase this value 
    } 
+0

更改爲255,仍然相同 –