I have two ListViews: listview and listview1. listview contains 7-8 columns and the last column contain an EditText. I want to show two ListViews with no spaces and they should be filled.
Here is my code:
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ShowTwoListView">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:weightSum="1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/lvFoods"
android:background="#000000"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
<ListView
android:id="#+id/lvRestaurants"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"/>
</LinearLayout>
</RelativeLayout>
Items
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivFoods"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
This is my result:
Your sub view needs to match its parents width
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivFoods"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Related
The title isn't good but i didn't know how else to describe
I have a relative layout with 2 elements, some container and a button at bottom.
I want the container fill all the space in the relativelayout leaving just the space enough to put the button
here is an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout //i'm using linearlayout as an example, it could be anything here
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/b3"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="asdasdasdasdasdasdasdasd" />
</RelativeLayout>
here is how i want it look like
The red means the relavitive layout, the green the linear layout, and the yellow means the button...
how can i make it?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/red"
android:padding="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/b"
android:background="#color/green">
</LinearLayout>
<Button
android:id="#+id/b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="this is the button"
android:background="#color/yellow"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/b3"
android:layout_margin="4dp"
android:background="#color/colorPrimary"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/b3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="asdasdasdasdasdasdasdasd" />
</RelativeLayout>
This should give you something close to what you want:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout //i'm using linearlayout as an example, it could be anything here
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_weight="1"
android:text="asdasdasdasdasdasdasdasd" />
</LinearLayout>
Good morning guys,
I am having a bit of trouble resolving an issue and could use some help. I created an XML resource file called comment__layout. For some reason I cannot get the layout to display full screen. Please can you review the XML code and help. As you will see in the screenshot the Comment layout is loaded over the parent layout which is exactly what I want however, I would like the Comment layout to be full screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/comment__layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_grey">
<LinearLayout
android:id="#+id/comment_heading__layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Comments"
android:textSize="20sp"
android:textColor="#color/gps_orange"
android:textStyle="bold"/>
<Button
android:id="#+id/comment_close__button"
android:layout_width="40dp"
android:layout_height="40dp"
android:text="X"/>
</LinearLayout>
<LinearLayout
android:id="#+id/comments_add_comment__layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/comment_add__edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/comment_add__button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+Add"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/comments_text_views__scroll_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/comments_text_views__layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
</LinearLayout>
</LinearLayout>
PARENT XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/component_wizard_layout_parent__relative"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/component_wizard_layout_parent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/frame_component_wizard_manager"/>
<LinearLayout
android:id="#+id/component_wizard_component_popup__layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
I have to scroll both the horizontal listview and vertical listview in single activity.
Below I have posted a screenshot for that:
activity_main.xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/home_layout_top"
android:scrollbars="none"
>
<RelativeLayout
android:id="#+id/rl_container_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/inc_ads_horizon"
layout="#layout/ads_horizontal_listview_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_people_know"
layout="#layout/people_you_know_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/inc_ads_horizon"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_listview"
layout="#layout/tab_home_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/inc_people_know"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/no_user_posts_item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/txt_no_posts_available"
android:textColor="#color/txt_common_black"
android:textSize="#dimen/txt_size" />
</RelativeLayout>
</ScrollView>
tab_home_list_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ListView
android:id="#+id/lv_post_home_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="5dp"
android:scrollbars="none"
android:transcriptMode="alwaysScroll"
android:visibility="gone" />
</LinearLayout>
ads_horizontal_listview_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_child"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
people_you_know_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_second_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
I tried with scrollview.It is not possible to scroll.Let me know is there any other ways to solve this issue.
If I scroll vertical listview to top, it is scrolling vertical listview only.If I am scrolling horizontal listview to the top, it is scrolling both vertical and horizontal listivew.But when I am scolling up, horizontal listview is hiden.
You can get the required views by customizing ScrollView & HorizontalScrollView.
Can check this post https://arunbadole1209.wordpress.com/2011/10/03/how-to-make-simultaneous-scrollable-views-in-android/
Use this xml layout, customize item views according to your actual need:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- You can define layout manager here also-->
<android.support.v7.widget.RecyclerView
android:id="#+id/ads_horizon"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/people_know"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/post_home_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
I want to add a button at the end of a list view. I have the following xml file. The list view appears with its contents, but the button does not show up.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
</LinearLayout>
The problem is with the attribute android:layout_height="match_parent" in your ListView. match_parent means that the listview will fill all the space. The correct way is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="1"
android:id="#+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
</LinearLayout>
Your button is not shown because your ListView took the whole space hiding your button as you set its layout_height to match_parent. match_parent will take the whole available space. So change it to wrap_content like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_parent"
android:id="#+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
</LinearLayout>
wrap_content will wrap your view to the least available height/width without hiding anything or making anything unclear.
i have the same problem, and solved.
you only need wrap that layout into ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_transaction_history"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v7.widget.RecyclerView>
<Button
android:id="#+id/btn_history_load_more"
style="?borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingBottom="#dimen/margin_big"
android:paddingTop="#dimen/margin_large"
android:text="#string/text_btn_load_more"
android:textColor="#009CDE"
android:textSize="#dimen/text_size_medium" />
</LinearLayout>
</ScrollView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<Button
android:layout_alignParentBottom="true"
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
<ListView
android:layout_above="#id/download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/myListView" /></RelativeLayout>
I'm trying to use ExpandableListView with custom adapter in my project.
There is a result view of my activity with ExpandableListView:
How you can see, some rows doesn't have a right height and some lines are cropped.
What i do wrong?
There are my layout files
activity layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:layout_width="matc_parent"
android:layout_height="match_parent"
android:id="#+id/noticeList"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/empty"
android:text="#string/empty"/>
</LinearLayout>
and layout for item of ExpandableListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/noticeImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:id="#+id/noticeDate"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/noticeTitle"/>
</LinearLayout>
</LinearLayout>
Thanks all for answers.
The solution is use RelativeLayout instead LinearLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/noticeImage"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/noticeImage"
android:id="#+id/noticeDate"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/noticeTitle"
android:layout_toRightOf="#+id/noticeImage"
android:layout_below="#+id/noticeDate"
/>
</RelativeLayout>
Try to set layout_height for TextView noticeDate to wrap_content
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/noticeImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/noticeDate"/>
<TextView
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/noticeTitle"/>
</LinearLayout>
</LinearLayout>