những gì tôi đang cố gắng làm là để nhúng một cái nhìn tùy chỉnh trong main.xml bố trí mặc định:
<?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">
<com.lam.customview.CustomDisplayView
android:id="@+id/custom_display_view1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/prev"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="50"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/prev" />
</LinearLayout>
</LinearLayout>
như bạn có thể nhìn thấy lớp được gọi là com. lam.customview.CustomDisplayView, với id của custom_display_view1.
bây giờ trong lớp com.lam.customview.CustomDisplayView, tôi muốn sử dụng bố cục khác được gọi là custom_display_view.xml vì tôi không muốn tạo các điều khiển/tiện ích theo chương trình.
custom_display_view.xml chỉ là một nút và một hình ảnh, nội dung trong đó tôi muốn thay đổi dựa trên một số điều kiện:
<?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"
>
<TextView
android:id="@+id/display_text_view1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/display_image_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
tôi đã cố gắng để làm:
1)
public CustomDisplayView(Context context, AttributeSet attrs) {
super(context, attrs);
try
{
// register our interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
View.inflate(context, R.layout.custom_display_view, null);
...
nhưng có lỗi này, "03-08 20: 33: 15.711: ERROR/onCreate (10879): Dòng tệp XML nhị phân # 8: Lỗi khi tăng cấp lớp java.lang.reflect.Constructor ".
2)
public CustomDisplayView(Context context, AttributeSet attrs) {
super(context, attrs);
try
{
// register our interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
View.inflate(context, R.id.custom_display_view1, null);
...
nhưng đã nhận lỗi này ", 03-08 20: 28: 47,401: ERROR/CustomDisplayView (10806): Resource ID # 0x7f050002 loại # 0x12 không hợp lệ "
cũng vậy, nếu tôi làm theo cách này, như ai đó đã đề xuất, không rõ với tôi như thế nào e custom_display_view.xml được liên kết với lớp chế độ xem tùy chỉnh.
cảm ơn.
Ngôn ngữ? Khung? –
hi i do có cùng một vấn đề ... u có giải pháp nào ??? – Ads