1

I want to make a View that consists of few other standard elements. There are ProgressBar, TextViews and ImageView. I declared how to layout them in 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> 

I also created a new class, but do not know how can I bind it to this resource file...

import android.content.Context; import android.view.View; public class QueueRowView extends View { public QueueRowView(Context context) { super(context); } } 

How can I make my control look like specified in layout file?

1 Answer 1

1

Is there a reason why you need a separate class for this layout? You could just include this layout file into another one. If you really want the extra class, then look at Fragments.

Sign up to request clarification or add additional context in comments.

2 Comments

I want it to be an element of a static list, so probably the best solution is to make it a separete View.
If it's a list then just inflate the layout in the getView() method of your adapter. You can add all the custom logic to the adapter too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.