どこから始めればよいかわかりません。先週アプリを作成しており、順調に進んでおり、今すぐカスタム ビューが必要です。http://developer.android.com/guide/topics/ui/custom-components.htmlを見てきました。でもね…どうやってつなぎ合わせたらいいのかわからない。ナンバー ピッカーを左側に配置し、テキストと画像を右側に配置して、ナンバー ピッカーのクリックをリッスンできるようにしたいのですが...正直なところ、どこから始めればよいかわかりません。
1997 次
1 に答える
2
レイアウトを使用してコンポーネントを結合します。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>
このレイアウトをリストの行として使用するには: BaseAdapter を拡張するカスタム リスト アダプターを作成し、リスト アダプターをカスタム リスト アダプターに設定し、アダプターの getView メソッドを次のようにオーバーライドします。
@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;
}
于 2011-05-24T19:32:08.460 に答える