在我的應用程序中,我需要使用ViewFlipper通過拖動觸摸屏切換屏幕。我有一個包含一些項目的ListView。當選擇一個項目時,我必須顯示一些圖像。問題在於圖像數量因物品不同而不同。所以我認爲我必須以編程方式創建LinearLayout和ImageView。我有可能做什麼?ViewFlipper與可變數量的liniar佈局
在此先感謝..
這裏是我試過的代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#000000"
android:id="@+id/layout_main">
<ViewFlipper android:id="@+id/details"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</ViewFlipper>
</LinearLayout>
和onCreate()方法:
for (int i = 0; i < jArray.length(); i++) {
LinearLayout l=new LinearLayout(this);
l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
l.setBackgroundColor(0xFFFFFFFF);
l.setOrientation(LinearLayout.VERTICAL);
ImageView img = new ImageView(this);
img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
//ImageView img1 = (ImageView) findViewById(R.id.photo1);
Drawable image1 = ImageOperations(getBaseContext(), url[i]);
img.setImageDrawable(image1);
l.addView(img);
}
但沒有任何反應。我只看到一個大黑屏。
你添加的LinearLayout到viewflipper?代碼中未顯示該部分 – blessenm
這是問題所在。謝謝:) – Gabrielle