ScrollView doesn't show the upper part of XML in android -
my xml working perfectly, has listview, set of textviews, imageviews , buttons. added scroll view entire layout. listview stopped functioning , added custom class in order t o make work. working intended, issue top part of layout not visible when xml loads, have scroll see top part of it. issue same still provided solutions don't work: scrollview doesn't show top part xml file:
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_default" android:orientation="vertical" > <linearlayout android:id="@+id/navigation_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/navigation" android:baselinealigned="false" android:orientation="horizontal" > <relativelayout android:layout_width="0dip" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_weight="1" > <textview android:id="@+id/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:layout_gravity="center_horizontal|center_vertical" android:textcolor="#057afb" android:textsize="19sp" android:textstyle="bold" /> </relativelayout> </linearlayout> <linearlayout android:id="@+id/navigation_layout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/navigation_layout" android:baselinealigned="false" android:orientation="horizontal" > <relativelayout android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:paddingtop="10dp" > <imageview android:id="@+id/app_icon" android:layout_width="75dp" android:layout_height="75dp" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="23dp" android:layout_margintop="14dp" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> <button android:id="@+id/btn_install" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_aligntop="@+id/app_icon" android:layout_marginright="36dp" android:background="@drawable/list_apps_install_button_selector" /> <textview android:id="@+id/txt_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/app_icon" android:layout_below="@+id/app_icon" android:text="desription goes here" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/txt_desc_long" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/app_icon" android:layout_below="@+id/app_icon" android:text="desription goes here" android:textappearance="?android:attr/textappearancesmall" android:visibility="gone"/> <textview android:id="@+id/txtmore" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_marginright="14dp" android:text="...more" android:textcolor="#057afb" /> </relativelayout> </linearlayout> <linearlayout android:id="@+id/navigation_layout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/navigation_layout1" android:baselinealigned="false" android:orientation="horizontal" > <relativelayout android:layout_width="0dip" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_weight="1" > <textview android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="2dp" android:layout_alignparentleft="true" android:layout_below="@+id/txt_desc" android:layout_margintop="15dp" android:background="@drawable/separator_app_details" /> <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/information" android:layout_below="@+id/information" android:layout_marginleft="50dp" android:layout_margintop="5dp" android:text="@string/version" android:textappearance="?android:attr/textappearancesmall" android:textcolor="#929292" /> <textview android:id="@+id/txt_version" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/textview3" android:layout_alignbottom="@+id/textview3" android:layout_marginleft="22dp" android:layout_torightof="@+id/textview3" android:text="small text" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/textview5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/textview3" android:layout_below="@+id/textview3" android:text="@string/uploader" android:textappearance="?android:attr/textappearancesmall" android:textcolor="#929292" /> <textview android:id="@+id/textview7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview5" android:layout_below="@+id/textview5" android:text="@string/updated" android:textappearance="?android:attr/textappearancesmall" android:textcolor="#929292" /> <textview android:id="@+id/textview9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/information" android:layout_below="@+id/textview7" android:text="@string/size" android:textappearance="?android:attr/textappearancesmall" android:textcolor="#929292" /> <textview android:id="@+id/textview11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/textview9" android:layout_below="@+id/textview9" android:text="@string/compatibility" android:textappearance="?android:attr/textappearancesmall" android:textcolor="#929292" /> <textview android:id="@+id/txt_uploader" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textview7" android:layout_alignleft="@+id/txt_version" android:text="small text" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/txt_updated" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/txt_uploader" android:layout_below="@+id/txt_uploader" android:text="small text" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/txt_size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textview11" android:layout_alignleft="@+id/txt_updated" android:text="small text" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/txt_compat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/textview11" android:layout_alignbottom="@+id/textview11" android:layout_alignleft="@+id/txt_size" android:text="small text" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/information" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="14dp" android:layout_margintop="19dp" android:text="@string/txt_info" android:textcolor="#000000" android:textsize="19sp" /> </relativelayout> </linearlayout> <linearlayout android:id="@+id/navigation_layout3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/navigation_layout2" android:layout_margintop="15dp" android:baselinealigned="false" android:orientation="horizontal" > <relativelayout android:layout_width="0dip" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_weight="1" > <textview android:id="@+id/older_versions" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="14dp" android:layout_margintop="10dp" android:text="@string/old" android:textcolor="#000000" android:textsize="19sp" /> <listview android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/older_versions" android:divider="@null" > </listview> </relativelayout> </linearlayout> <textview android:id="@+id/textview01" android:layout_width="fill_parent" android:layout_height="2dp" android:layout_alignparentleft="true" android:layout_aligntop="@+id/navigation_layout3" android:background="@drawable/separator_app_details" /> </relativelayout> </scrollview>
this class written make both scroll view , list view function @ same time:
public class utility { public static void setlistviewheightbasedonchildren(listview listview) { listadapter listadapter = listview.getadapter(); if (listadapter == null) { // pre-condition return; } int totalheight = 0; (int = 0; < listadapter.getcount(); i++) { view listitem = listadapter.getview(i, null, listview); listitem.measure(0, 0); totalheight += listitem.getmeasuredheight(); } viewgroup.layoutparams params = listview.getlayoutparams(); params.height = totalheight + (listview.getdividerheight() * (listadapter.getcount() - 1)); listview.setlayoutparams(params); } }
put in oncreate()
method:
final scrollview scrollview = ((scrollview) findviewbyid(r.id.scrollview)); scrollview.post(new runnable() { @override public void run() { scrollview.fullscroll(scrollview.focus_up); } });
the code above provides way force scroll of scrollview
@ upper position. behavior can caused weight
attribute in layouts etc. "debugging" of take more time apply solution above , there isn't guarantee can know each time disturbs initial scroll position.
Comments
Post a Comment