我正在尝试创建一个自定义视图,然后在我的布局中使用该自定义视图。
我的自定义视图被调用NodePickup
,我有两个文件:
- 资源/布局/nodepickup.xml
- src/com.codeshogun.android.swipesample/NodePickup.java
nodepickup.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="48dip"
android:background="#aa0000"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ImageView01"
android:layout_width="48dip"
android:layout_height="48dip"
android:background="#FFFFFF"
android:src="@drawable/arrow_up_green" >
</ImageView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<TextView
android:id="@+id/time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="14:46 (15 min), 1 res"
android:textColor="#000000"
android:textSize="12dip" >
</TextView>
<TextView
android:id="@+id/road"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Karl XII gatan 6"
android:textColor="#000000"
android:textSize="12dip" >
</TextView>
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bertil Håkansson"
android:textColor="#000000"
android:textSize="12dip" >
</TextView>
</LinearLayout>
</LinearLayout>
NodePickup.java:
package com.codeshogun.android.swipesample.CustomViews;
import com.codeshogun.android.swipesample.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
public class NodePickup extends LinearLayout {
public NodePickup(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.nodepickup, this);
}
}
我正在尝试将此视图/小部件添加到布局文件 main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.codeshogun.android.swipesample.CustomViews"
android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000" />
<!-- If I try to add it here, it wont work -->
<com. <!-- <-- will not give me the widget...? -->
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00FF00" />
</LinearLayout>
</ViewFlipper>
我究竟做错了什么?