android - Check condition 仅显示和动态列表查看具有不同高度的所有项目

标签 android listview

1.检查条件只显示

public View getView(final int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.main_alllatestnewslist, parent,
                false);     
    ImageView imageview = (ImageView) vi
            .findViewById(R.id.image_alllatestnewstitle);
    imageview.setVisibility(View.INVISIBLE);
    TextView titletext = (TextView) vi
            .findViewById(R.id.text_particularlatestnewstitle);
    TextView categorytext = (TextView) vi
            .findViewById(R.id.text_newscategorytitle);
    TextView datetext = (TextView) vi.findViewById(R.id.text_newsdate);

    if (!imagepath[position].toString().equals("no picture")) {
        imageLoader.DisplayImage(imagepath[position], imageview);
        imageview.setVisibility(View.VISIBLE);          
        titletext.setWidth(460 - imageview.getWidth() - 5); <-- this line   
    } else {
        imageview.setVisibility(View.INVISIBLE);
        imageview.setImageDrawable(null);
    }
    titletext.setText(title[position].toString());
    categorytext.setText(category[position].toString());
    datetext.setText(date[position].toString());

    return vi;
}

第一次查看列表时无法检查该语句,导致 textview 与 imageview 堆叠。滚动一次或多次后,它只会向左移动。

如何在显示之前进入这个声明?

<强>2。根据条件以编程方式在 ListView 中设置所有项目的高度

RelativeLayout childlayout = (RelativeLayout)vi.findViewById(R.id.layout_childlist);

这是项目的布局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_childlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/list_bg"
android:minHeight="?android:attr/listPreferredItemHeight" >
<LinearLayout
    android:id="@+id/test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="5px"
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    android:layout_marginTop="5px" >

    <ImageView
        android:id="@+id/image_alllatestnewstitle"
        android:layout_width="140px"
        android:layout_height="80px"
        android:scaleType="centerCrop" />
</LinearLayout>
....
</RelativeLayout>

例如,其中一项需要 80 像素才能显示,而其他项只需要 40 像素。但是,其他项目不会换行到 40px 并换行到 80px 并使所有项目具有相同的高度。

如何设置不同高度的所有项目的高度?

最佳答案

试试 imageview.setVisibility(View.GONE);

INVISIBLE 只隐藏 View ,而 GONE “删除”它

关于android - Check condition 仅显示和动态列表查看具有不同高度的所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10632770/

相关文章:

android - 使用 Robolectric 测试 okHttp 请求 - 回调

android - getApplicationContext()' 在非 Activity 中使用 volley 的空对象引用

android - 关于 NotifyDataSetChanged

android - 获取与 BindView 中的 ListView 项关联的 ContextMenu

java - 我如何将 TwitterFeed (JSON) 解析为自定义 ListView ?

Android 谷歌地图版本 2 显示方向和谷歌地图图标

java - 每次打开应用程序时都需要密码验证

android - 如何将视频文件上传到android中的网络服务器?

java - 使用 Picasso Library 目标不能为空

JavaFX 中的 ListView 样式