我有從網址加載的圖像的水平列表。所以我有一個ImageLoader,然後是適配器,然後是我的活動。我的XML佈局看起來是這樣的:Android ImageView動態寬度和高度
mainlayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/hlist_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always" >
</com.devsmart.android.ui.HorizontalListView>
</LinearLayout>
然後我list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:translationY="200dp" > <!-- make this dynamic -->
<FrameLayout
android:id="@+id/mainlayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ImageView
android:id="@+id/prof_pic"
android:clickable="true"
android:adjustViewBounds="true"
android:layout_width="360dp"
android:layout_height="360dp" />
<ProgressBar
android:id="@+id/img_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<TextView
android:id="@+id/sname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<TextView
android:id="@+id/sdesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
採用這種佈局,其結果是圖A.灰色的破行是imageView,我們實際上看不到它,但只有那些圖像(綠色框)。我想實現的是一個如圖B
所以,在一定程度上解決這個問題,我試圖將我的ImageView
<ImageView
android:id="@+id/prof_pic"
android:clickable="true"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="360dp"
android:maxHeight="360dp"
android:minHeight="240dp"
android:minWidth="240dp"
/>
但是,什麼情況是,到時候我打開應用程序,我的圖像列表看起來像圖A.但是當沿着圖像滾動時,它調整爲有點像圖B.但是當我滾動回第一張圖像時,只有第一張圖像纔會顯示或者有時,我的圖像列表從我的第二張圖像開始。這真的很瘋狂。
有沒有什麼方法可以實現圖B而不破壞我的圖像列表或者在應用程序開始時它已經顯示如圖B?
編輯:
這是我的適配器的樣子:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if(convertView == null){
convertView = inflater.inflate(R.layout.list_layout, null);
holder = new ViewHolder();
holder.txtShopName = (TextView) convertView.findViewById(R.id.shop_name);
holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
holder.imageView = (ImageView) convertView.findViewById(R.id.prof_pic);
holder.progBar = (ProgressBar) convertView.findViewById(R.id.img_progress);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
imageLoader=new ImageLoader(context.getApplicationContext(), holder.progBar);
SRowItem sItem = (SRowItem) getItem(position);
holder.txtName.setText(sItem.getShopName());
holder.txtDesc.setText(sItem.getShopDesc());
imageLoader.DisplayImage(sItem.getImageUrl(), holder.imageView);
return convertView;
}
我剛纔已經回答您的其他問題,所以我看到這一個來自鏈接它。我在這個問題中看到的最重要的信息是你的Adapter的getView方法是什麼樣的,你使用的是什麼控件(com.devsmart.android.ui.HorizontalListView)。它看起來像每個列表項是圖像視圖的包裝,並且列表項正在被專門測量以佔用相同的空間量。 – Rich
我編輯了我的問題,幷包含了我的Adapter的getView。 [com.devsmart.android.ui.HorizontalListView](https://github.com/mtparet/HorizontalListView/blob/master/HorizontalListView.java) – elL