简体   繁体   中英

Android: Create Horizontal List View but Image size cannot be set

I'd like to create an Horizontal List View. And I reference this http://www.dev-smart.com/archives/34

But it set ImageView size 150dp in "listitem.xml"

<ImageView
      android:id="@+id/image"
      android:layout_width="150dip"
      android:layout_height="150dip"
      android:scaleType="centerCrop"
      android:src="@drawable/icon"
      />

I tried to change the width and height of the ImageView, but it's useless.

It seems that in the HorizontalListView.java, the function "addAndMeasureChild()" has set

child.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
                MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));

But I change the MEasureSpec to EXACTLY or others, it's still useless.

Anyone can figure out this?

Thanks in advance.

Eric

MeasureSpec.makeMeasureSpec(getWidth()...是列表视图的宽度,尝试用params.width替换getWidth(),这对我来说是使用固定大小的布局,在您的情况下是imageview。如果您使用MATCH_PARENT或WRAP_CONTENT,则无法使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM