-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看起來是這樣的:
從圖中可以看出,我的子元素(edittext,密碼區,按鈕)並不清晰可見樂。
我的問題:
1.How實現像上面我必須到另一個可繪製適用於內 '的LinearLayout'?
2.是否可以更改文本字段,按鈕的alpha級別以便它更清晰可見?
更改爲255,仍然相同 –