tôi xác định một drawable
Cách sử dụng hình dạng XML có thể vẽ được?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http//schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffffff" />
<size android:width="60dp"
android:height="40dp" />
</shape>
Nhưng làm thế nào để sử dụng nó trong định nghĩa layout
?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:src="@drawable/ic_title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</LinearLayout>
Tôi vẫn chỉ thấy nền đen.
được sửa đổi:
Hóa ra tôi đã bỏ lỡ một :
trong tờ khai drawable
xmlns
. Bây giờ ví dụ này hoạt động trong thiết bị Gingerbread :)
Câu hỏi ngớ ngẩn, nhưng là 'ic_title' tên của bạn có thể vẽ được không? Ngoài ra, bạn có thể đặt 'android: background' trên' LinearLayout' –
có, ic_title là ký tự tôi đã xác định ở trên. Tôi không muốn đặt android: background, đó không phải là hiệu ứng mong muốn. Tôi có thể đặt thêm ImageView vào LinearLayout. –