列表视图不在某些设备上显示

时间:2014-05-15 07:14:54

标签: android listview

我有一个ListView,我正在填充ArrayAdapter.Its可以正常工作大多数设备。但我有一个无法显示列表的karbonn(320x480)设备。我的应用程序包含许多列表视图,它们在karbonn上正确显示。< / p>

我的.xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e6f0f5"
    tools:context=".Save_educationActivity" >



    <RelativeLayout
        android:id="@+id/btnlayout"
        android:layout_width="match_parent"
        android:layout_height="47dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#4791FF"
        android:orientation="horizontal" >


        <ImageButton
            android:id="@+id/xibtn_save_education"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="5dp"
            android:background="#4791FF"
            android:src="@drawable/ic_action_save" />

        <ImageButton
            android:id="@+id/xibtn_back_to_education"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:background="#4791FF"
            android:src="@drawable/ic_action_back" />
    </RelativeLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnlayout"
        android:layout_marginTop="3dp"
        android:text="@string/Education_title" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=" Course Name"
                android:textSize="18dp"
                android:textStyle="bold" />


        </RelativeLayout>
    </ScrollView>

    <EditText
        android:id="@+id/xedt_course"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/scrollView1"
        android:ems="10"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/xedt_course"
        android:text="Date"
        android:textSize="18dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView3"
        android:text="Joining Date"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView01"
        android:layout_alignBottom="@+id/TextView01"
        android:layout_alignLeft="@+id/lvdate"
        android:text="Leave Date"
        android:textSize="18dp" />

    <EditText
        android:id="@+id/jdate"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/TextView01"
        android:ems="10"
        android:hint="Joining Date"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/lvdate"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/TextView02"
        android:ems="10"
        android:hint="Leaving Date"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/jdate"
        android:layout_marginTop="10dp"
        android:background="#ffffff"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_education_desc"
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:background="@drawable/date_stroke"
            android:text="Add Description"
            android:textColor="#ffffff"
            android:textSize="20dp" />

        <ImageButton
            android:id="@+id/add_edu_desc"
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:background="@drawable/date_stroke"
            android:src="@drawable/ic_action_new"
            android:visibility="gone" />
    </LinearLayout>

       <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_below="@+id/linearLayout1">


           <ListView
        android:id="@+id/lst_eductndesc"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true" >

    </ListView>

    </RelativeLayout>

</RelativeLayout>

2 个答案:

答案 0 :(得分:2)

你的布局非常错误。我会告诉你旅游错误:

<RelativeLayout
    android:id="@+id/btnlayout"
    android:layout_width="match_parent"
    android:layout_height="47dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#4791FF"
    android:orientation="horizontal" > // there is no such attribute in relative layout


    <ImageButton
        android:id="@+id/xibtn_save_education"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="5dp"
        android:background="#4791FF"
        android:src="@drawable/ic_action_save" />

    <ImageButton
        android:id="@+id/xibtn_back_to_education"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:background="#4791FF"
        android:src="@drawable/ic_action_back" />
</RelativeLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btnlayout"
    android:layout_marginTop="3dp"
    android:text="@string/Education_title" />

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" // which size of scroll view you expected here? It will grow with their content and never have scroll.
    android:layout_below="@+id/textView1" >

    <RelativeLayout // you don't need to have relative layout here.
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" Course Name"
            android:textSize="18dp"
            android:textStyle="bold" />


    </RelativeLayout>
</ScrollView>

<EditText
    android:id="@+id/xedt_course"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/scrollView1"
    android:ems="10"
    android:inputType="textPersonName" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/xedt_course"
    android:text="Date"
    android:textSize="18dp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView3"
    android:text="Joining Date"
    android:textSize="18dp" />

<TextView
    android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/TextView01"
    android:layout_alignBottom="@+id/TextView01"
    android:layout_alignLeft="@+id/lvdate"
    android:text="Leave Date"
    android:textSize="18dp" />

<EditText
    android:id="@+id/jdate"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/TextView01"
    android:ems="10"
    android:hint="Joining Date"
    android:inputType="textPersonName" />

<EditText
    android:id="@+id/lvdate"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/TextView02"
    android:ems="10"
    android:hint="Leaving Date"
    android:inputType="textPersonName" >

    <requestFocus />
</EditText>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_below="@+id/jdate"
    android:layout_marginTop="10dp"
    android:background="#ffffff"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btn_education_desc"
        android:layout_width="170dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:background="@drawable/date_stroke"
        android:text="Add Description"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <ImageButton
        android:id="@+id/add_edu_desc"
        android:layout_width="70dp"
        android:layout_height="match_parent"
        android:background="@drawable/date_stroke"
        android:src="@drawable/ic_action_new"
        android:visibility="gone" />
</LinearLayout>

   <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"  // which height you expect here? It will have height the same as parent, but draws somewhere at the bottom. It will draw a large part of view outside of screen.
    android:layout_below="@+id/linearLayout1">


       <ListView
    android:id="@+id/lst_eductndesc"
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerHorizontal="true" >

</ListView>

</RelativeLayout>

我认为您需要重新格式化您的布局。如果您将向图像显示您想要实现的内容并解释它的行为,我将帮助您编写更有效且更干净的xml。

你可以像这样制作你的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e6f0f5"
    tools:context=".Save_educationActivity" 
     android:orientation="vertical">



    <RelativeLayout
        android:id="@+id/btnlayout"
        android:layout_width="match_parent"
        android:layout_height="47dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#4791FF"
        android:orientation="horizontal" > // there is no such attribute in relative layout


        <ImageButton
            android:id="@+id/xibtn_save_education"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="5dp"
            android:background="#4791FF"
            android:src="@drawable/ic_action_save" />

        <ImageButton
            android:id="@+id/xibtn_back_to_education"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:background="#4791FF"
            android:src="@drawable/ic_action_back" />
    </RelativeLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:text="@string/Education_title" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="50dp" // you must declare your height exactly here
>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=" Course Name"
                android:textSize="18dp"
                android:textStyle="bold" />


    </ScrollView>


    <EditText
        android:id="@+id/xedt_course"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/scrollView1"
        android:ems="10"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/xedt_course"
        android:text="Date"
        android:textSize="18dp"
        android:textStyle="bold" />

    <LinearLayout layout_width="match_parent"
layout_height="wrap_content"
android:orientation="horizontal">
    <LinearLayout layout_width="0dp"
laout_weight="1"
layout_height="wrap_content"
android:orientation="vertical">

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView3"
        android:text="Joining Date"
        android:textSize="18dp" />

<EditText
        android:id="@+id/jdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Joining Date"
        android:inputType="textPersonName" />

</LinearLayout>
    <LinearLayout layout_width="0dp"
laout_weight="1"
layout_height="wrap_content"
android:orientation="vertical">


    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Leave Date"
        android:textSize="18dp" />
    <EditText
        android:id="@+id/lvdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Leaving Date"
        android:inputType="textPersonName" >

    </EditText>
</LinearLayout>
</LinearLayout>
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:background="#ffffff"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_education_desc"
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:background="@drawable/date_stroke"
            android:text="Add Description"
            android:textColor="#ffffff"
            android:textSize="20dp" />

        <ImageButton
            android:id="@+id/add_edu_desc"
            android:layout_width="70dp"
            android:layout_height="match_parent"
            android:background="@drawable/date_stroke"
            android:src="@drawable/ic_action_new"
            android:visibility="gone" />
    </LinearLayout>

           <ListView
        android:id="@+id/lst_eductndesc"
        android:layout_width="match_parent" 
        android:layout_height="0dp"
layout_weight="1" 
        android:layout_centerHorizontal="true" >


</LinearLayout>

答案 1 :(得分:0)

由于您正在使用RelativeLayouts并将视图彼此对齐,因此布局可能会超出屏幕底部。

我鼓励您使用不同的ViewGroup组合,例如在ScrollView中使用垂直方向的LinearLayout。

相关问题