在自定义视图中组合android组件
我不知道从哪里开始,我在过去的一周里一直在构建一个应用程序,并且已经取得了很好的进展,现在需要一个自定义视图。我已经看过了。 但是,嗯……不知道怎么把它拼凑起来。在自定义视图中组合android组件,android,textview,imageview,android-custom-view,Android,Textview,Imageview,Android Custom View,我不知道从哪里开始,我在过去的一周里一直在构建一个应用程序,并且已经取得了很好的进展,现在需要一个自定义视图。我已经看过了。 但是,嗯……不知道怎么把它拼凑起来。 我想把数字选择器放在左边,一些文本和图像放在右边,并且能够听到数字选择器上的点击。。。老实说,我不知道从哪里开始 我会使用布局来组合组件。用xml定义布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" androi
我想把数字选择器放在左边,一些文本和图像放在右边,并且能够听到数字选择器上的点击。。。老实说,我不知道从哪里开始 我会使用布局来组合组件。用xml定义布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<NumberPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
/>
<ImageView
android:id="@+id/image"
android:layout_toRightOf="@id/picker"
android:src="..."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
/>
<TextView
android:id="@+id/text"
android:text="some text"
android:layout_toRightOf="@id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
/>
</RelativeLayout>
}我想可能会这样做,但我需要创建一个列表,因此我认为最好有一个组合视图……我编辑了我的答案,以显示如何将此布局用作列表的行。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
//if convertView is null, inflate a view.
//otherwise reuse the convertView
if(convertView == null)
{
view = mInflater.inflate(R.layout.filebrowserrow, null);
}
else
{
view = convertView;
}
//retrieve picker to set listeners, initialize values, etc
NumberPicker picker = (NumberPicker)view.findViewById(R.id.picker);
//retrieve ImageView to change image, etc
ImageView image = (ImageView)view.findViewById(R.id.image);
//retrieve TextView to change text, etc
TextView text = (TextView)view.findViewById(R.id.text);
return view;