我想制作一个由其他几个标准元素组成的视图。有ProgressBar、TextViews 和ImageView。我在 res/layout/myView.xml 中声明了如何布局它们
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
tools:ignore="HardcodedText,ContentDescription" >
<ImageView
android:id="@+id/qItemImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/qItemNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/qItemImageView"
android:gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ProgressBar
android:id="@+id/qProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/qItemNameTextView"
android:layout_alignParentRight="true"
android:layout_below="@+id/qItemNameTextView"
android:max="100"
android:progress="50" />
<TextView
android:id="@+id/qLevelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/qItemImageView"
android:layout_alignTop="@id/qItemImageView"
android:text="7"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/qTimeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/qProgressBar"
android:layout_alignLeft="@id/qProgressBar"
android:layout_alignRight="@id/qProgressBar"
android:layout_alignTop="@id/qProgressBar"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="01:01:01"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
</RelativeLayout>
我还创建了一个新类,但不知道如何将它绑定到这个资源文件...
import android.content.Context;
import android.view.View;
public class QueueRowView extends View {
public QueueRowView(Context context) {
super(context);
}
}
如何使我的控件看起来像布局文件中指定的那样?