相关疑难解决方法(0)

为什么ListView项目不会增长以包装其内容?

我有一个相当复杂的ListView,具有可变列表项高度.在某些情况下,我需要在列表项中显示一个附加视图,默认情况下隐藏它(View.GONE).通过启用它(View.VISIBLE),列表项的高度增加(或者至少应该增加).

问题:即使我将项目的根布局声明为wrap_content,并且将项目中的每个组件声明为fill_parent,我隐藏/显示应该更改项目高度的视图只是在底部而不是其父级切断(项目布局)在高度上增长以完全显示它.

是否有任何与ListView相关的问题以及我可能错过的项目布局和项目高度?

更多观察:

出于测试目的,我现在已经将列表项布局简化为仅包含根LinearLayout和ImageView.当我将LinearLayout高度设置为例如200dip并将ImageView设置为fill_parent时,我原本期望ImageView增长直到达到其父级设置的200dip限制.

但是,图像将只是与其位图资源一样高(就好像我已将其设置为wrap_content)并且整个列表项将具有相同的高度(即,就好像我已将其设置为wrap_content一样).

但是,如果我将图像高度设置为例如200dip,则列表项的高度将增加,项目布局也将增加.

换句话说,完全忽略列表项布局的layout_height,因此除了硬编码像素值之外,ImageView上的任何高度值也是如此.

android listview

56
推荐指数
4
解决办法
7万
查看次数

ViewGroup {TextView,...}.getMeasuredHeight给出的错误值小于实际高度

  { January 14, 2011... I have given up to use setListViewHeightBasedOnChildren(ListView listView},
  instead, I don't put my listview in a scrollview, and then just put other contents
  into a listview by using ListView.addHeaderView() and ListView.addFooterView(). 
  http://dewr.egloos.com/5467045 }
Run Code Online (Sandbox Code Playgroud)

ViewGroup(ViewGroup包含具有除line-feed-character之外的长文本的TextView).getMeasuredHeight返回错误的值...小于实际高度.

如何摆脱这个问题?

这是java代码:

    /*
    I have to set my listview's height by myself. because
    if a listview is in a scrollview then that will be
    as short as the listview's just one item.
    */
    public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = …
Run Code Online (Sandbox Code Playgroud)

android

9
推荐指数
2
解决办法
6215
查看次数

ListView的Layout_width

好的,我遇到了listView的attribut layout_width的问题.

在我的项目中,我的listview的背景图像不符合屏幕的宽度.所以我在wrap_content上设置了layout_width,并且我将listView水平居中.

看起来这是一个坏主意,因为在适配器中,GetView方法被调用的次数是显示的单元格数的3倍以上.如果我在fill_parent上设置layout_width,问题就解决了.我创建了一个显示问题的简单项目.

这是活动的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

item_list xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>
Run Code Online (Sandbox Code Playgroud)

最后活动:

package fr.example.android.listviewbug;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class ExampleListViewBugActivity extends ListActivity{
    public static int cpt;

    public static final String[] COUNTRIES = new String[] {
        "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
        "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", …
Run Code Online (Sandbox Code Playgroud)

android listview

5
推荐指数
2
解决办法
9402
查看次数

scrollview中的ExpandableListView

在我的应用程序中,我想创建一个具有ExpandableListView并在他下面CheckBox的页面.

我的问题是我的ExpandableListView太大,使CheckBox不在页面中.

在较小的屏幕上根本看不到.

我试图将ExpandableListView放在scrollview中,但它不起作用.

有没有办法让我的设计?

这是我的代码和截图.

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="15sp"
                android:text="In this page you can save a group of exercise under one routine."
                android:textColor="@color/Black"
                android:textSize="20sp" />

            <ExpandableListView
                android:id="@+id/instructionsExView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/textView1"
                android:layout_marginTop="15sp" >
            </ExpandableListView>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/instructionsExView"
                android:layout_marginTop="15sp"
                android:text="If you want to open the instruction again check &apos;need help?&apos;"
                android:textColor="@color/Black"
                android:textSize="20sp" />

            <CheckBox
                android:id="@+id/checkInstructions"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

xml android android-layout android-xml

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×4

listview ×2

android-layout ×1

android-xml ×1

xml ×1