嗨,我在基于TextView的高度设置ImageView的高度时遇到问题,这是我正在使用的代码:
@Override
public void onBindViewHolder(@NonNull final viewHolder holder, final int position) {
holder.abstractText.setText(events.get(position).abstractTExt);
Rect bounds = new Rect();
Paint textPaint = holder.abstractText.getPaint();
textPaint.getTextBounds((String) holder.abstractText.getText(),0,holder.abstractText.getText().length(),bounds);
holder.abstractText.post(new Runnable() {
@Override
public void run() {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, holder.abstractText.getHeight() + 300);
holder.borderImage.setLayoutParams(layoutParams);
}
});
}
问题在于,直到我开始滚动RecyclerView时,一切都运转良好,当我滚动图像的高度小于TextView时,如何解决此问题?
答案 0 :(得分:0)
主结构必须是这样的:(RelativeLayout的高度= wrap_content,TextView的高度= wrap_content,ImageView的高度= match_parent)
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"/>
<ImageView
android:id="@+id/imageview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/any"/>
</RelativeLayout>
并且如果您使用的是RecycyclerView,请在此托盘输入:
@Override
public int getItemViewType(int position) {
return position;
}