Reputation: 5900
I Have listview in my xml file. Below listview I have other layouts. If I set android:layout_weight="1" in listview then after changing orientation it does not scroll and only layout below listview is visible . If I remove layout_weight="1" from listview then without changing orientation also listview is not visible. Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/applogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient" >
<TextView
android:id="@+id/beforelogo"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/logo"
android:layout_width="141dp"
android:layout_height="46dp"
android:layout_centerInParent="true"
android:background="@drawable/logo" />
<ImageButton
android:id="@+id/afterlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/beforelogo"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/logout" />
</RelativeLayout>
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:paddingTop="15dip" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:text="CASH BILL"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:enabled="false"
android:inputType="datetime" />
<ImageView
android:id="@+id/calendar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1"
android:src="@drawable/calendar" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="vertical">
<ListView
android:id="@+id/cash_bill_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1" />
<RelativeLayout
android:id="@+id/other_charges_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cash_bill_list"
android:padding="2dp" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/other_charges_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Other Charges"
android:textSize="@dimen/rating" />
<!-- day open -->
<TextView
android:id="@+id/other_charges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/other_charges_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="@dimen/rating" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/security_tax_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/other_charges_layout"
android:padding="2dp" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/security_tax_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Security Tr. T"
android:textSize="@dimen/rating" />
<!-- day open -->
<TextView
android:id="@+id/security_tax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/security_tax_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="@dimen/rating" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/serice_tax_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/security_tax_layout"
android:padding="2dp" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/serice_tax_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Service Tax"
android:textSize="@dimen/rating" />
<!-- day open -->
<TextView
android:id="@+id/serice_tax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/serice_tax_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="@dimen/rating" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/stamp_duty_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/serice_tax_layout"
android:padding="2dp" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/stamp_duty_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Stamp Duty"
android:textSize="@dimen/rating" />
<!-- day open -->
<TextView
android:id="@+id/stamp_duty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/stamp_duty_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="@dimen/rating" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/due_to_you_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/stamp_duty_layout"
android:padding="2dp" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/total_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Total"
android:textSize="@dimen/rating" />
<!-- day open -->
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/total_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="@dimen/rating" />
</RelativeLayout>
</LinearLayout>
What should I do so listview is visible and after changing orientation scroll is also available. Thanks in advance
Upvotes: 0
Views: 241
Reputation: 2482
So here is my result. I think you should let the list view be 1/2 of the screen and with the rest of the elements add them a ScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- HEADER -->
<RelativeLayout
android:id="@+id/applogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/RedishColor">
<TextView
android:id="@+id/beforelogo"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/logo"
android:layout_width="141dp"
android:layout_height="46dp"
android:layout_centerInParent="true"
android:background="@color/GreenSeaColor" />
<ImageButton
android:id="@+id/afterlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/beforelogo"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/view_icon" />
</RelativeLayout>
<!-- TOP BAR -->
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:paddingTop="15dip">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:text="CASH BILL"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:enabled="false"
android:inputType="datetime" />
<ImageView
android:id="@+id/calendar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<!-- LISTVIEW -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<ListView
android:id="@+id/cash_bill_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.1" />
<!-- BOTTOM PART -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/other_charges_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cash_bill_list"
android:padding="2dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/other_charges_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Other Charges"
android:textSize="20sp" />
<!-- day open -->
<TextView
android:id="@+id/other_charges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/other_charges_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/security_tax_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/other_charges_layout"
android:padding="2dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/security_tax_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Security Tr. T"
android:textSize="20sp" />
<!-- day open -->
<TextView
android:id="@+id/security_tax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/security_tax_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/serice_tax_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/security_tax_layout"
android:padding="2dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/serice_tax_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Service Tax"
android:textSize="20sp" />
<!-- day open -->
<TextView
android:id="@+id/serice_tax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/serice_tax_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/stamp_duty_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/serice_tax_layout"
android:padding="2dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/stamp_duty_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Stamp Duty"
android:textSize="20sp" />
<!-- day open -->
<TextView
android:id="@+id/stamp_duty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/stamp_duty_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/due_to_you_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/stamp_duty_layout"
android:padding="2dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/total_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Total"
android:textSize="20sp" />
<!-- day open -->
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/total_txt"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Result Images:
VERTICAL
HORZIONTAL
Upvotes: 1
Reputation: 1463
You are missing a </LinearLayout>
. I do not know if this will solve the problem. Also usually if you add the weight attribute you would add it to the other elements in that LinearLayout so that the layout can weight all the elements properly. By adding just the weight attribute, the other elements may by getting a 0 weight by default and hence would not be shown.
Upvotes: 1