I'm using TabHost and inside of one tab, I inserted ListView. I set all height's to fill_parent. But it doesn't show full list, but only part of it. What to do to make tab contents fill screen by height?
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bkg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="7dp"
android:background="#drawable/gradientrounded"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/taxisign" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/taxiprofiletitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="0.9"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<Button
android:id="#+id/phonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:background="#drawable/button"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Button"
android:textColor="#ffffff" />
</LinearLayout>
<ProgressBar
android:id="#+id/loadFeedbacks"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:visibility="invisible" />
</LinearLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF0000" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:background="#FF000000"
android:layout_height="wrap_content" >
<TextView
android:tag="tab0"
android:text="Инфо"
android:background="#android:drawable/btn_star_big_on"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab1"
android:text="Отзывы"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab2"
android:text="Тарифы"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/profile_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:text="Добавить"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
android:id="#+id/reviewslist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/tariffslist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</ScrollView>
On your very first LinearLayout change the layout_height="match_parent". Also, fill_parent has been deprecated since API 8 and replaced with match_parent so that is what you should be using instead.
You have used wrap content for your listView height. You should always use height as match_parent/fill_parent. I guess your problem is here
<ListView
android:id="#+id/reviewslist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
change it to:
<ListView
android:id="#+id/reviewslist"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
Adding to that, this layout seems to be innefcient. Listviews inside scrollviews are not recommended.
It does seem while quickly viewing the XML file that the parent of your TabHost (LinearLayout) is 'wrap_content' so I am not sure that you are getting all the parents. I do desire a better UI interface for building visuals through Eclipse. Not too happy to work out issues like this when they come up. And they can come up frequently. Usually it involves some trial and error to get things looking the way I want.
Scroll Layout was unnecessary, removing it, made code to work
Related
I am getting scroll in list view in even though there is enough space below list view. height is WRAP_CONTENT. I will not able to give it fill_parent or match_parent due to my design.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/header_back_blue"
android:gravity="center_vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/first_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/header_title_text"
style="#style/headerBlueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Home" />
<ImageView
android:id="#+id/last_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:onClick="openSettings"
android:src="#drawable/settings_icon" />
</RelativeLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header"
android:background="#android:color/transparent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#color/listview_back_grey" >
<RelativeLayout
android:id="#+id/rl_settings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/settings_bg"
android:visibility="gone" >
<!-- Here I am getting scroll -->
<ListView
android:id="#+id/setting"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#color/white"
android:divider="#color/settings_divider"
android:dividerHeight="2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp" >
</ListView>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" />
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/transparent"
android:divider="#null" />
</LinearLayout>
</TabHost>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:onClick="openAddNewTask"
android:src="#drawable/center_circle" />
</RelativeLayout>
Sorry, i cant share image due to less reputation
you shouldn't be using wrap_content for your listview. you probably should change something about your layout. Perhaps use weight to get the desired size, like suggested here: https://stackoverflow.com/a/7588931/4498224
and here https://stackoverflow.com/a/11295287/4498224
If you don't want your list to scroll at all, you probably shouldn't be using a list. Maybe try to use a linearlayout and fill it in in your code.
I'm using Listview to show the search result ,but why it doesn't fit my parent view?I want to make it fill the rest Linearlayout zoom,Please help me,thanks.
xml file:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/search_et"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="3"
android:background="#null"
android:gravity="center"
android:textColor="#ffffff"
android:hint="输入要查找的内容" />
<Button
android:id="#+id/search_btn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="搜索"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</ScrollView>
Never use ListView within a ScrollView.
Quoting docs
You should never use a ScrollView with a ListView, because ListView
takes care of its own vertical scrolling. Most importantly, doing this
defeats all of the important optimizations in ListView for dealing
with large lists, since it effectively forces the ListView to display
its entire list of items to fill up the infinite container supplied by
ScrollView.
If you use LinearLayout use weights for LinearLayout and ListView.
You can use a RelativeLayout. There is no need for a ScrollView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/ll"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/search_et"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="3"
android:background="#null"
android:gravity="center"
android:textColor="#ffffff"
android:hint="输入要查找的内容" />
<Button
android:id="#+id/search_btn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="搜索"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="#+id/lv"
android:layout_below="#+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
Snap
remove the scrollview from the layout
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/search_et"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="3"
android:background="#null"
android:gravity="center"
android:hint="输入要查找的内容"
android:textColor="#ffffff" />
<Button
android:id="#+id/search_btn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:text="搜索" />
</LinearLayout>
<ListView
android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
please look my code fist ,I want to make the layout like below picture ,but the two listViews not work :
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:baselineAligned="false">
<LinerLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"><!-- here is the problem-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:text="#string/Subdistrict"/>
<ListView
android:id="#+id/Subdistrict"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinerLayout>
<LinerLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:text="#string/Building"
android:textColor="#ffffff"/>
<ListView
android:id="#+id/Building"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinerLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/BuildingSelectOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/OK"/>
<Button
android:id="#+id/BuildingSelectCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Cancel"/>
</LinearLayout>
</LinearLayout>
I want to realize the layout like the image below:
but the two listView doesn't show at all , what i have missed? someone help me please.thank you.
"height" to "0dp" though your list will calculate itself. and "weight" to 7? Is it needed?
Yes it is, have a look at these questions :
Android: trying to understand android:layout_weight
Need help in understand layout_weight="1"
So here is my suggesttion:
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="80"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#2fff0000"
android:layout_weight="50">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:text="Subdistrict"/>
<ListView
android:id="#+id/Subdistrict"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#2f00ff00"
android:layout_weight="50">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:text="Building"
android:textColor="#ffffff"/>
<ListView
android:id="#+id/Building"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:gravity="center" >
<Button
android:id="#+id/BuildingSelectOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"/>
<Button
android:id="#+id/BuildingSelectCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</LinearLayout>
When you run the app, you will see that the LinearLayout wrap 2 ListView have different background colors, so the ListView are shown, so I think the problem is that you forget to set Adapter for them.
Give it a try and please tell me the result.
i have two layouts vertically , first one has edittext and button, second one has two listvies ,
the first one doesn't appear, and i got an exception when running the application
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/etRestaurantSearchName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter name"
android:inputType="text"
android:textSize="15dip" />
<Button
android:id="#+id/bRestaurantSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ListView
android:id="#+id/lvRestaurants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:fillViewport="true" >
</ListView>
<ListView
android:id="#+id/lvAlphabets"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#drawable/foods_alphabets_bg"
android:orientation="vertical" >
</ListView>
</LinearLayout>
</RelativeLayout>
i ma sure it is something about hiegh , width or weight,
You have used RelativeLayout as the parent layout for the inner two layouts. Therefore the second inner Linear Layout overlaps the first one , thus first one cant be seen. Make use of linear layout as parent layout
Try this:
Correction :
android:layout_below="#+id/Layout1" for layout two.
and some weight related changes.
<LinearLayout
android:id="#+id/Layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/etRestaurantSearchName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter name"
android:inputType="text"
android:textSize="15dip" />
<Button
android:id="#+id/bRestaurantSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Layout1"
android:orientation="horizontal" >
<ListView
android:id="#+id/lvRestaurants"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/edit_text"
android:fillViewport="true" >
</ListView>
<ListView
android:id="#+id/lvAlphabets"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="#drawable/btn_bg_pressed"
android:orientation="vertical" >
</ListView>
</LinearLayout>
I am trying to make my button centered horizontally and 2/3 down from the top vertically. I want it to remain 2/3 from the top no matter what the screen size/density. Here is the button I am trying to move:
<Button
android:id="#+id/btnResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="250dp" />
Thanks!
Working Code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<Button
android:id="#+id/btnResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<TextView
android:id="#+id/tvCounter2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
To archive this you need to use LineareLayout and explore weight feature. To get it work it must be something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<Button
android:id="#+id/btnResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
Hope it helps!
You can use the attribute "layout_weight"