TextView中重叠的CardView内的ImageView

TextView中重叠的CardView内的ImageView

本文介绍了TextView中重叠的CardView内的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做CardViews的一个ListView。
该CardView含有在底部的顶部和几个TextViews一个ImageView的。
我能做到的一切权利,但由于某种原因,图像不适合CardView(所以它能够在它的顶部裁剪)和TextViews重叠图像的其余部分。
我尝试了很多不同的解决方案,虽然没有工作对我来说,我cam't找出原因。

I'm trying to do a ListView of CardViews.The CardView contains an ImageView at the top and several TextViews at the bottom.I manage to do everything right, although for some reason the image don't fit the CardView (so it gets cropped at the top of it) and the TextViews overlaps the rest of the image.I tried a lot of different solutions, although nothing worked for me and i cam't figure out why.

主要布局:
    

The main layout:

    <ListView android:id="@+id/item_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></ListView>

</LinearLayout>

该CardView布局:

The CardView layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin">

    <android.support.v7.widget.CardView android:id="@+id/item_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView android:id="@+id/item_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <TextView android:id="@+id/item_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

            <TextView android:id="@+id/item_image_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView android:id="@+id/item_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

而getView()methid:

And the getView() methid:

public View getView(int position, View convertView, ViewGroup parent) {
        View cardView;

        if (convertView == null) {
            LayoutInflater inflater = ((Activity) this.getContext()).getLayoutInflater();
            cardView = inflater.inflate(R.layout.item_card_list, parent, false);
        }
        else {
            cardView = convertView;
        }

        ImageView itemImage = (ImageView)cardView.findViewById(R.id.item_image);
        TextView itemTitle = (TextView)cardView.findViewById(R.id.item_title);
        TextView imgDesc = (TextView)cardView.findViewById(R.id.item_image_desc);
        TextView itemDesc = (TextView)cardView.findViewById(R.id.item_desc);

        Item currItem = this.getItem(position);

        itemImage.setImageDrawable(currItem.mImageDrawable);
        itemTitle.setText(currItem.mTitle);
        imgDesc.setText(currItem.mDescription.imageDesc);
        itemDesc.setText(currItem.mDescription.descText);

        itemImage.setScaleX((float)1000 / currItem.mImageDrawable.getMinimumWidth());
        itemImage.setScaleY((float)1000 / currItem.mImageDrawable.getMinimumWidth());

        return (cardView);
    }

这似乎是CardViews有一个最大高度或something..can't告诉:(

It seems like the CardViews have a max height or something..can't tell :(

在此先感谢!

推荐答案

我的做法是完全错误的。我意识到,我所用的setScale()方法只缩放位图,而不是ImageView的本身。虽然当我试图调整前的ImageView有人甚至奠定下来的画布上,我没有任何运气。所以,我没有这样的:

My approach was all wrong. I realized that the setScale() methods I used only scaled the bitmap, and not the ImageView itself. Although when I tried to resize the ImageView before it was even layed down on the canvas, I got no luck either. So I did this:

而不是试图调整大小的ImageView我用小位分配后,我调整了自己的位图其设置为ImageView的面前。固定一切:)

Instead of trying to resizing the ImageView after I assigned it with a small bitmap, I resized the bitmap itself before setting it to the ImageView. Fixed everything :)

这篇关于TextView中重叠的CardView内的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:09