ANDROID :: custom ListView仅显示第一个LinearLayout Child

时间:2014-05-28 09:00:46

标签: android android-layout listview android-listview

HERE是我自定义ListView的xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:custom="http://schemas.android.com/apk/res/com.prototype.auinsight.schedual_listview"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:id="@+id/wrapper">

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        <ImageView
                android:layout_width="0dp"
                android:layout_height="35dp"
                android:id="@+id/imgDay" android:layout_weight=".1"
                android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                android:layout_marginLeft="12dp"/>
        <com.prototype.auinsight.schedual_listview.CustomView_Schedule
                android:layout_width="0dp"
                android:layout_height="35dp"
                android:id="@+id/view"
                custom:labelColor="@android:color/white"
                custom:timelineColor="@color/slate"
                android:layout_weight=".8"
                android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/>
        <ImageView
                android:layout_width="0dp"
                android:layout_height="35dp"
                android:id="@+id/imgUpDown" android:scaleType="fitXY" android:src="@drawable/down"
                android:layout_weight=".1" android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="12dp"/>
    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtTime1" android:text="09:00" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="ENGLISH IV"
                android:id="@+id/txtSubject1" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"
                android:background="@color/subject_alizarin" android:textColor="#ffffff"/>
    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtTime2" android:text="09:00" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="ENGLISH IV"
                android:id="@+id/txtSubject2" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"
                android:background="@color/subject_alizarin" android:textColor="#ffffff"/>
    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtTime3" android:text="09:00" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="ENGLISH IV"
                android:id="@+id/txtSubject3" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"
                android:background="@color/subject_alizarin" android:textColor="#ffffff"/>
    </LinearLayout>
    <LinearLayout android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtTime4" android:text="09:00" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="ENGLISH IV"
                android:id="@+id/txtSubject4" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"
                android:background="@color/subject_alizarin" android:textColor="#ffffff"/>
    </LinearLayout>
    <LinearLayout android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtTime5" android:text="09:00" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="ENGLISH IV"
                android:id="@+id/txtSubject5" android:paddingLeft="10dp" android:paddingRight="10dp"
                android:paddingTop="5dp" android:paddingBottom="5dp" android:textSize="20sp"
                android:background="@color/subject_alizarin" android:textColor="#ffffff"/>
    </LinearLayout>


</LinearLayout>

这是我的适配器

   @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        viewHolder vh = null;

        if(v == null){

            vh = new viewHolder();
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.schedual_listview,null);
            v.setBackgroundResource(R.drawable.custom_middle_listview);

            vh.wrapper = (LinearLayout) v.findViewById(R.id.wrapper);
            vh.imgDay = (ImageView) v.findViewById(R.id.imgDay);
            vh.customView = (CustomView_Schedule) v.findViewById(R.id.view);
            vh.txtTime1 = (TextView) v.findViewById(R.id.txtTime1);
            vh.txtTime2 = (TextView) v.findViewById(R.id.txtTime2);
            vh.txtTime3 = (TextView) v.findViewById(R.id.txtTime3);
            vh.txtTime4 = (TextView) v.findViewById(R.id.txtTime4);
            vh.txtTime5 = (TextView) v.findViewById(R.id.txtTime5);
            vh.txtSubject1 = (TextView) v.findViewById(R.id.txtSubject1);
            vh.txtSubject2 = (TextView) v.findViewById(R.id.txtSubject2);
            vh.txtSubject3 = (TextView) v.findViewById(R.id.txtSubject3);
            vh.txtSubject4 = (TextView) v.findViewById(R.id.txtSubject4);
            vh.txtSubject5 = (TextView) v.findViewById(R.id.txtSubject5);


            v.setTag(vh);

        }else{
            vh = (viewHolder)v.getTag();
        }

        Schedule_lvItem schedule_lvItem = scheduleLvItems.get(position);

        vh.imgDay.setImageResource(schedule_lvItem.getDay());
        vh.customView.setSubjectData(schedule_lvItem.getSubjectData());
        vh.txtTime1.setText("09:00");
        vh.txtTime2.setText("10:30");
        vh.txtTime3.setText("12:00");
        vh.txtTime4.setText("13:30");
        vh.txtTime5.setText("15:00");
        vh.txtSubject1.setText("ENGLISH IV");
        vh.txtSubject2.setText("MACRO");
        vh.txtSubject3.setText("STRATEGIC TECHNOLOGY MANAGEMENT");
        vh.txtSubject4.setText("DATA COMMUNICATION");
        vh.txtSubject5.setText("OBJECT ORIENTED PROGRAMMING");

        AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
                AbsListView.LayoutParams.FILL_PARENT,
                schedule_lvItem.getCurrentHeight()
        );
        vh.wrapper.setLayoutParams(layoutParams);

        schedule_lvItem.setWrapper(vh.wrapper);

        v.setTag(vh);

        return v;
    }

    public class viewHolder{
        LinearLayout wrapper;
        ImageView imgDay;
        CustomView_Schedule customView;
        TextView txtTime1;
        TextView txtTime2;
        TextView txtTime3;
        TextView txtTime4;
        TextView txtTime5;
        TextView txtSubject1;
        TextView txtSubject2;
        TextView txtSubject3;
        TextView txtSubject4;
        TextView txtSubject5;
    }

第一个LinearLayout在屏幕上可见,而其他不在

注意::这适用于ListView的单行项目

我目前正在使用幻灯片动画创建可扩展的ListView。

此布局将包含展开效果之前和之后的作用。

我做错了什么? PLZ建议。

1 个答案:

答案 0 :(得分:1)

由于FILL_PARENT

,您的第一个linearlayout正在从其父级获取完整空间
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:custom="http://schemas.android.com/apk/res/com.prototype.auinsight.schedual_listview"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:id="@+id/wrapper">

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">  <===  here

将其替换为:android:layout_height="wrap_content"应解决您的问题。

使用带有heith的父级wrap_content和高度为fill_parent的子级具有不可预测的结果,因为两者都依赖于它们的大小。

顺便说一下,“FILL_PARENT”已被弃用,它已被重命名为“MATCH_PARENT”。