水平方向にスクロール可能ないくつかのビューを保持するはずの horizontalscrollview を作成しようとしています。
初期ビューは、内部にリニア レイアウトを含む水平スクロール ビューです。
別のビューがあります。都市の天気を表示する画面のようなものです。
データベースに 5 つの都市がある場合、ビューの 5 つのインスタンスを水平スクロール ビューに追加したいと考えています。また、各インスタンスには、クリックや http リクエストなどの独自のイベントがあります。
xml から horizontalscrollview を作成できますが、動的に作成したいと考えています。出発点を得るためにいくつかの例を探してきましたが、何もないようです。
誰かが私を正しい方向に向けることができますか?
これは私の horizontalscrollview xml です
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_height="50dp"
android:id="@+id/TableRow01" android:layout_width="fill_parent"
android:background="#82db7a">
<ImageView android:id="@+id/imageView1" android:src="@drawable/logo_topbar"
android:layout_height="wrap_content" android:layout_width="wrap_content" />
<ImageButton android:background="@drawable/topicon_btn"
android:src="@drawable/btn_icon_locateme" android:layout_gravity="center_vertical"
android:layout_height="45dp" android:id="@+id/locatemebtn"
android:layout_width="wrap_content" android:layout_centerVertical="true"
android:layout_alignParentRight="true" android:layout_margin="5dp" />
<ImageButton android:background="@drawable/topicon_btn"
android:src="@drawable/btn_icon_star" android:layout_height="45dp"
android:id="@+id/favbtn" android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/locatemebtn" android:layout_alignTop="@+id/locatemebtn"
android:layout_alignBottom="@+id/locatemebtn" />
</RelativeLayout>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:fillViewport="true"
android:id="@+id/scrollView1" android:layout_height="fill_parent"
android:layout_width="fill_parent" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android_id="@+id/mainScroll">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
これは、ビューを追加しようとした方法です(機能するかどうかをテストするためだけに、機能するかどうかはわかりませんが、ビューは単なるレイアウトまたは機能を備えたレイアウトです)
LinearLayout mainscroll=(LinearLayout) findViewById(R.id.mainScroll);
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = vi.inflate(R.layout.weather_tab, null);
mainscroll.addView(view);
スクロールビューには子が 1 つしかないため、内部に linearlayout を追加しました (線形レイアウトにする必要があるかどうかはわかりません)。ビューのすべてのインスタンスを線形レイアウトに追加したいと考えています。
PS: iPhone にも同じアプリケーションを実行しましたが、それほど苦痛はありませんでした。Androidは私を混乱させすぎているようです:(