Why my Android Listview is not scrolling? - android

I have made a xml display with some items . But my listView of that xml is not scrolling. I have made a scrollView and the listView is inside the scrollView , is it a problem ? If I design display with keeping the listView out side the scrollView, then the lisViw is not showing on my android device display. I need such a display where need a scrollView and scrolling listview. My code is given below.
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/head_logo" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/cardlistButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/head_menu04" />
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#ffffff" />
<Button
android:id="#+id/cameraButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/head_menu02" />
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#ffffff" />
<Button
android:id="#+id/homeButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/head_menu03" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/title_detail"
android:gravity="right|center_vertical" >
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingTop="15dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dip"
android:orientation="horizontal" >
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:gravity="left"
android:text="STATUS :"
android:textColor="#666666"
android:textStyle="bold" />
<TextView
android:id="#+id/pdtvText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text=""
android:textColor="#666666"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dip"
android:orientation="horizontal" >
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:gravity="left"
android:text="注文日 :"
android:textColor="#666666"
android:textStyle="bold" />
<TextView
android:id="#+id/pdtvText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text=""
android:textColor="#666666"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dip"
android:orientation="horizontal" >
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:gravity="left"
android:text="納品日 :"
android:textColor="#666666"
android:textStyle="bold" />
<TextView
android:id="#+id/pdtvText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text=""
android:textColor="#666666"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dip"
android:orientation="horizontal" >
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:gravity="left"
android:text="依頼枚数 :"
android:textColor="#666666"
android:textStyle="bold" />
<TextView
android:id="#+id/pdtvText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text=""
android:textColor="#666666"
android:textStyle="bold" />
<TextView
android:id="#+id/pdtvText41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text=""
android:textColor="#FF0000"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dip"
android:orientation="horizontal" >
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:gravity="left"
android:text="納品枚数 :"
android:textColor="#666666"
android:textStyle="bold" />
<TextView
android:id="#+id/pdtvText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text=""
android:textColor="#666666"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/errorLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/subtitle_error"
android:gravity="right|center_vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/bluebar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/subtitle_deli"
android:gravity="right|center_vertical" >
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:gravity="left"
android:paddingBottom="5dip"
android:paddingTop="5dip"
android:text=" "
android:textColor="#666666"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageviewproduct"
android:layout_width="300dip"
android:layout_height="180dip"
android:layout_marginBottom="10dip"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="11.89" >
<ListView
android:id="#+id/productlistall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000" >
</ListView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</merge>

Never add ListView,MapView,WebView(its already scrollable) in ScrollView
Remove from ScrollView.

Do not put a ListView inside a ScrollView.
ListView already handles
scrolling, you're only going to run into trouble.
Using a ListView to make it not scroll is extremely expensive and goes against the whole purpose of ListView. You should NOT do this. Just use a LinearLayout instead.

As samir and coader said, never use them in scrollview; but let this time be an exception, first check whether you've entered enough no. of items inside the list such tat there is enough no. of objects to scroll

Related

Centerr aligned UI components not scrolling up/down properly if added in ScrollVIew

There seems to be an ui scrolling issue when we center aligned all UI components using scrollview and taps on edittext which pops-up keyboard then not all ui scrolling up/down properly if added in ScrollVIew. There seems to problem with the current approach as its not allowing us to adjust after using all available layout features. I did searched on internet to fix this but not found a solution.
I did used android:windowSoftInputMode="adjustResize"
If anyone can suggest a solution that would be quite helpful.
Code snippet::
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/grey"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/topbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/topbar"
android:gravity="center_horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:gravity="center"
android:src="#drawable/dash_logo" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center" >
<TextView
style="#style/iAccetpTitle"
android:layout_gravity="center"
android:layout_margin="10dip"
android:text="#string/welcome" />
<LinearLayout
android:id="#+id/eureka_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/rounded_rectangle"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingTop="10dp" >
<TextView
android:id="#+id/enter_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="8dp"
android:singleLine="false"
android:text="#string/enter_number"
android:textColor="#color/grey_black"
android:textSize="16sp" />
<EditText
android:id="#+id/phone_number_edittext"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/iaccept_mobiletextfield"
android:gravity="center"
android:inputType="number"
android:maxLength="10"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:textColor="#666666"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="15dp" >
<TextView
android:id="#+id/enter_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="2dp"
android:singleLine="false"
android:text="#string/enter_email"
android:textColor="#color/grey_black"
android:textSize="16sp" />
<EditText
android:id="#+id/email_edittext"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/iaccept_mobiletextfield"
android:hint="#string/email_hint"
android:inputType="textEmailAddress"
android:maxLength="49"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:textColor="#666666"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_termscondtion" />
<Button
android:id="#+id/terms_n_cond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/terms_cond_selector" />
</LinearLayout>
<Button
android:id="#+id/iaccept_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="10dip"
android:background="#drawable/iaccept_selector"
android:onClick="onClick"
android:text="#string/i_accept"
android:textColor="#drawable/white"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<!-- </ScrollView> -->
</ScrollView>
</LinearLayout>
Remove android:layout_gravity="center" from the inner LinearLayout of ScrollView.
It should work.

ListView in android should come in whole screen and other elements in the bottom

There is a list view and other text views in my screen.
I want to show the list in whole the screen and other elements in the bottom of the list.
Below is the code I used.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relative_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_light_blue" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_light_blue"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/header1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/header_gradients"
android:orientation="vertical"
android:paddingBottom="8dip"
android:paddingTop="8dip" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:gravity="center"
android:text="#string/shopping_cart"
android:textColor="#color/white"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_light_blue"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:background="#color/white"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:id="#+id/purchase_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="2dp"
android:text="Requisitioner"
android:textColor="#color/black"
android:textSize="15sp"
android:typeface="sans" />
<TextView
android:id="#+id/requisitioner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/purchase_order"
android:layout_marginBottom="3dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:text="Requisitioner"
android:textColor="#color/black"
android:textSize="15sp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="#string/image"
android:src="#drawable/shopping_cart" />
</RelativeLayout>
<TextView
android:id="#+id/products_and_services"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="#string/products_and_services"
android:textColor="#color/black"
android:textSize="17sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/lr1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="0.12" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/pagingPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lr1"
android:background="#drawable/background_light_blue"
android:orientation="vertical" >
<TextView
android:id="#+id/note_to_approver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="#string/note_to_approver"
android:textColor="#color/black"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:background="#color/white"
android:maxLines="10"
android:padding="5dp"
android:text="hijnjn"
android:textColor="#color/black"
android:textSize="15sp"
android:typeface="sans" />
<TextView
android:id="#+id/approver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="#string/approvers"
android:textColor="#color/black"
android:textSize="17sp"
android:textStyle="bold" />
<Button
android:id="#+id/approvers"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/options_menu"
android:drawableRight="#drawable/arrow_right"
android:gravity="left|center"
android:text="#string/approvers"
android:textColor="#color/black"
android:textSize="16sp"
android:textStyle="bold"
android:typeface="sans" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#layout/btn_background" >
<Button
android:id="#+id/release_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#drawable/btn_blue"
android:text="Approve(1)/Reject(0)"
android:textColor="#color/white"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
My requirement: Now the list is scrolling within the given area. I want to show in the whole screen and the scrolling should be only for the screen.
Please help me to do this.
You should not put a Vertically scrolling widget/view (ListView) in another vertically scrolling view (ScrollView). Though there are a few ways mentioned here and here which might help you achieve what you wish but that will increase the CPU load.

Issue with Relative Layout

I am working on my first android app and one issue that I have not been able to find the solution is with the relative layout and footer bar.
I have set up a relative layout with a button bar at the bottom. It works find if there is enough content in the other linear layout; however, when there is not enough content to fill out the page, the content is aligned at the bottom on top of the button bar. I would like it to be aligned at the top with the button bar remaining on the bottom. I have tried every align top option I can find and setting the content height to fill_parent/match_parent, but all of those cause the items inside of the linear layout to disappear.
How can I fix this?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#c9c9c9" >
<LinearLayout
android:id="#+id/bottom_control_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/btnComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/content_new_event"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="#string/BtnComment"
android:textColor="#797979"
android:textSize="14sp" />
<Button
android:id="#+id/btnMeToo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/social_add_group"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="#string/BtnMeToo"
android:textColor="#797979"
android:textSize="14sp" />
<Button
android:id="#+id/btnFlag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/flag"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="#string/BtnFlag"
android:textColor="#797979"
android:textSize="14sp" />
<Button
android:id="#+id/btnShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/social_share"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="#string/BtnShare"
android:textColor="#797979"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottom_control_bar"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:background="#ffffff"
android:gravity="top"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/ticket_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<ImageView
android:id="#+id/ticket_owner_image2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:background="#797979"
android:contentDescription="#string/StdImageDesc"
android:padding="1dp"
android:scaleType="fitXY"
android:src="#drawable/picture" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/ticket_owner_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dip"
android:paddingLeft="5dip"
android:textColor="#595959"
android:textSize="10sp" />
<TextView
android:id="#+id/ticket_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="2dip"
android:paddingLeft="5dip"
android:textColor="#595959"
android:textSize="14sp" />
<TextView
android:id="#+id/ticket_create_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="2dip"
android:paddingLeft="5dip"
android:textColor="#595959"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
<TextView
android:id="#+id/ticket_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="5dip"
android:textColor="#595959"
android:textSize="14sp" />
</LinearLayout>
<ListView
android:id="#+id/commentlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#b5b5b5"
android:dividerHeight="1dp" />
</LinearLayout>
</RelativeLayout>
try the following and let me know if this what you want to achieve:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#c9c9c9" >
<ListView
android:id="#+id/commentlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:layout_below="#+id/linear1"
android:layout_above="#+id/bottom_control_bar"
android:divider="#b5b5b5"
android:dividerHeight="1dp" />
<LinearLayout
android:id="#+id/bottom_control_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/btnComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/dummy_heyzooka_icon_blue"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="aa"
android:textColor="#797979"
android:textSize="14sp" />
<Button
android:id="#+id/btnMeToo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/dummy_heyzooka_icon_blue"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="dd"
android:textColor="#797979"
android:textSize="14sp" />
<Button
android:id="#+id/btnFlag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/dummy_heyzooka_icon_blue"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="ff"
android:textColor="#797979"
android:textSize="14sp" />
<Button
android:id="#+id/btnShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:drawableLeft="#drawable/dummy_heyzooka_icon_blue"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:text="ff"
android:textColor="#797979"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:background="#ffffff"
android:gravity="top"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="horizontal" >
<TextView
android:id="#+id/ticket_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<ImageView
android:id="#+id/ticket_owner_image2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:background="#797979"
android:contentDescription="ada"
android:padding="1dp"
android:scaleType="fitXY"
android:src="#drawable/dummy_heyzooka_icon_blue" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/ticket_owner_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dip"
android:paddingLeft="5dip"
android:textColor="#595959"
android:textSize="10sp" />
<TextView
android:id="#+id/ticket_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="2dip"
android:paddingLeft="5dip"
android:textColor="#595959"
android:textSize="14sp" />
<TextView
android:id="#+id/ticket_create_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="2dip"
android:paddingLeft="5dip"
android:textColor="#595959"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
<TextView
android:id="#+id/ticket_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="5dip"
android:textColor="#595959"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Hi First of all when your working with relative layout be caution because if you change an alignment or any modifications on that layout it will disappear (or) it may change the alignment , So don't worry undo your layout u can come back to your previous alignment now you can modify one by one item in the layout.

Complex ListView item layout with all elements the same size for each item?

I am trying to build a complex listview item layout with all of the elements being the same dimensions for each listview item with the entire layout taking up the whole width of the screen. So far I have attempted doing this using a linearlayout and found that this is the wrong approach. I have then attempted using a relative layout however this has not worked for me so I hope that someone can point out how I can make this work.
Here is a diagram of what I am trying to build.
Here is some more details about the diagram:
Only elements 5 and 6 have the same content for every list item. The
rest of elements all will have different text however the layout
should always be the same size.
Element 4 should only be 2 lines. Elements 1, 2 and 3 should only be 1
line.
Element 2 should be aligned left and element 3 should be aligned
right.
Element 2 and 3 should each be half of the width of element 4.
Here is my attempt at this layout using a RelativeLayout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dp">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="20dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="#id/txtRaceNumber"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toRightOf="#id/txtRaceNumber" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceClass" />
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:paddingRight="8dip"
android:focusable="false"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceStartTime" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/btnTracklist" />
</RelativeLayout>
Using this RelativeLayout all of the elements appear scrambled within the layout.
How can I get all of these elements to align as I have shown in the Diagram?
Is this what you need?
<LinearLayout
android:id="#+id/lin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:text="TExt1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/lin1"
android:layout_toLeftOf="#+id/lin3">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lin3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:focusable="false"
android:paddingRight="8dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
try this code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:gravity="center|left"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left|center"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
I have managed to get the desired layout using weightSum on the main layout.
Here is the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/twolinechecked"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:maxHeight="?android:attr/listPreferredItemHeight"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:orientation="horizontal"
android:weightSum="1"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="6dip">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/linearTextInner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:maxLines="1"
android:layout_alignParentRight="true"
android:gravity="right" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_marginLeft="5dip"
android:paddingRight="8dip"
android:layout_gravity="center_vertical|center_horizontal" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignParentRight="true" />
</LinearLayout>
Follow below structure I feel you can achieve what you want use weight and weightSum.
<LinearLayout orientation="horizontal">
<LinearLayout>
<TextView/>
</LinearLayout>
<LinearLayout orientation="vertical">
<TextView/>
<LinearLayout orientation="horizontal">
<TextView/>
<TextView/>
</LinearLayout>
<ImageButton/>
<ImageView/>
</LinearLayout>
EDIT
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="2dp"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.7"
android:gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.3"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
</LinearLayout>

Webview inside a View pager in android

I have a WebView at the bottom of view in ViewPager... When I slide through the items of ViewPager. The View moves on down. (I guess the focus goes to webview)
I am not sure whether this is due to WebView.
Loading the webview with html data using
webView.loadDataWithBaseURL(null, data, "text/html","utf-8",null);
It's annoying when the page moves down every time the next item is loaded. I have an ImageView at the top of the View
Any pointers?
here is the xml:
<ScrollView
android:id="#+id/scroll_view_1"
style="#style/some_style"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none" >
<LinearLayout
android:id="#+id/linear_layout_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/some_drawable"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relative_layout_1"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:paddingLeft="5dip"
android:paddingRight="5dip" >
<LinearLayout
android:id="#+id/linear_layout_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dip"
android:gravity="center" >
<PageIndicator
android:id="#+id/page_indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relative_layout_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:visibility="visible" >
<TextView
android:id="#+id/text_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:text="1/50"
android:textColor="#000000"
android:textSize="16sp" />
<ImageView
android:id="#+id/image_view_1"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_marginRight="5dip"
android:layout_toLeftOf="#id/text_view_1"
android:scaleType="centerInside"
android:src="#drawable/some_drawable_3" />
<ImageView
android:id="#+id/image_view_2"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_marginRight="5dip"
android:layout_toLeftOf="#id/image_view_1"
android:scaleType="centerInside"
android:src="#drawable/some_drawable_4" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="relative_layout_3"
android:layout_height="wrap_content"
android:background="#f8f8f8"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dip"
android:paddingTop="5dip" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/some_drawbale_2" />
<TextView
android:id="#+id/text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="6dip"
android:gravity="left|center_vertical"
android:paddingLeft="3dip"
android:paddingRight="7dip"
android:text="$121.00"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<Button
android:id="#+id/button_1"
android:layout_width="95dip"
android:layout_height="30dip"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15sp"
android:background="#drawable/some_drawable_5"
android:gravity="center"
android:textSize="15dip" />
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/text_view_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:gravity="left"
android:lineSpacingExtra="2dip"
android:text="Some Text"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingTop="15dip" >
<WebView
android:id="#+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
I had the same kind of issue. And adding this attribute to the top most linear layout solved the issue. try this,
android:descendantFocusability="blocksDescendants".
In your case add this to your Linear Layout inside the ScrollView and check.

Categories

Resources