I'm trying to position a few Cardviews below eachother in a RelativeLayout, but it isn't working out so far. The cardviews are all on top of eachother, but layout_below is set for all of them. It's pretty strange, because it did work in the past if I recall correctly.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com"
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="something.something.fragments.RosterFragment"
android:id="#+id/relativeLayout"
android:background="#color/white"
tools:ignore="MergeRootFrame">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false"
android:id="#+id/rosterContainer0">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewMonday"
android:longClickable="true"
style="#style/InformationCard">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateMonday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewMonday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewTuesday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewMonday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Dinsdag"
android:id="#+id/dateTuesday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewTuesday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewWednesday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewTuesday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateWednesday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewWednesday"
android:layout_below="#+id/dateWednesday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewThursday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewWednesday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateThursday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewThursday"
android:layout_below="#+id/dateThursday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewFriday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewThursday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateFriday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewFriday"
android:layout_below="#+id/dateFriday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
Watch out when you copy - paste code.
All your cards have the attribute android:layout_alignParentTop="true"
Related
I want to get huge view, which I have to scroll. I want to get a one part of of view always on a phone screen in my code is a LinearLayout I want to display always on screen. Into my LinearLayout I put layout_alignParentTop but when I scroll it disappears.
My code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/iv_photo"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="3.5">
<TextView
android:id="#+id/tv_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jan Nowak"
android:textColor="#color/background_tutorial"
android:textSize="#dimen/text_normal_size"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_user_mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_user_name"
android:text="jan.nowak#gmail.com"
android:textColor="#color/background_tutorial"
android:textSize="#dimen/text_normal_size" />
</RelativeLayout>
<ImageView
android:id="#+id/iv_settings"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Made few changes:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<ImageView
android:id="#+id/iv_photo"
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="3.5">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_user_name"
android:textColor="#000000"
android:textSize="17sp"
android:text="Jan Nowak"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_user_name"
android:id="#+id/tv_user_mail"
android:textColor="#000000"
android:textSize="17sp"
android:text="jan.nowak#gmail.com"
/>
</RelativeLayout>
<ImageView
android:id="#+id/iv_settings"
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
If you want to keep a view static and other scrollable and keep that view outside of your scrollview....
I have main RelativeLayout layout file. I have scrollview and two buttons and listview inside this scrollview.I have one problem , when i run program it show's only one item in listview.my problem is xml file. How i can change my problem?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="#5f2585" >
<Button
android:id="#+id/studia"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/n_button"
android:text="სტუდია"
android:textColor="#ffffff" />
<ListView
android:id="#+id/menu_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/studia"
android:divider="#null"
>
</ListView>
<Button
android:id="#+id/gadacema"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/menu_listview"
android:background="#drawable/n_button"
android:text="გადაცემა"
android:textColor="#ffffff" />
</RelativeLayout>
in programmatically everything is ok(if i deleted scrollview,then i can show all values,but i cannot show button witch is a below in listview
What is wrong in my xml file. How can i solve this problem?
Please try this.
<ScrollView 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:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="#5f2585" >
<Button
android:id="#+id/studia"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/n_button"
android:text="სტუდია"
android:textColor="#ffffff" />
<ListView
android:id="#+id/menu_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/studia"
android:divider="#null"
>
</ListView>
<Button
android:id="#+id/gadacema"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/menu_listview"
android:background="#drawable/n_button"
android:text="გადაცემა"
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Try this:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/studia"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/n_button"
android:text="სტუდია"
android:textColor="#ffffff" />
<ListView
android:id="#+id/menu_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/studia"
android:divider="#null"/>
<Button
android:id="#+id/gadacema"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/menu_listview"
android:background="#drawable/n_button"
android:text="გადაცემა"
android:textColor="#ffffff" />
</RelativeLayout>
I have a listview in inside a RelativeLayout. The size of my relativelayour change according the size of my listview (number of rows). If it has only two rows, the relative layout stays larger. If it has more rows, the relative stays smaller.
This happen only in small devices.
What do I do?
EDIT: CODE BELOW
<LinearLayout 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"
android:background="#drawable/bg_cinza_transparente_98_porcento"
android:orientation="vertical"
tools:context=".AdicionarMarcaModeloActivity" >
<LinearLayout
style="#style/..."
android:layout_width="match_parent"
android:background="#color/cinza_escuro"
android:orientation="vertical" >
<RelativeLayout
style="#style/..."
android:orientation="vertical" >
<TextView
android:id="#+id/labelCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Marca"
android:textColor="#android:color/white"
android:textSize="22sp" />
<ImageView
android:id="#+id/imgCloseMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:src="#drawable/bt_close" />
</RelativeLayout>
<RelativeLayout
style="#style/..."
android:layout_width="match_parent"
android:background="#color/branco_gelo"
android:orientation="vertical" >
<TextView
android:id="#+id/labelSubCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="SELECIONE A MARCA DO SEU VEÍCULO"
android:textColor="#color/cinza_escuro_fontes_cabecalho" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
style="#style/..."
android:layout_width="match_parent"
android:orientation="horizontal" >
<ListView
android:id="#+id/lvMarcaModelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#drawable/line" >
</ListView>
</RelativeLayout>
// Try this way,hope this will help you to solve your problem...
<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="vertical" >
<TextView
android:id="#+id/labelCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Marca"
android:textColor="#android:color/white"
android:layout_gravity="center_horizontal"
android:textSize="22sp" />
<ImageView
android:id="#+id/imgCloseMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:src="#drawable/ic_launcher"
android:layout_marginTop="5dp"/>
<TextView
android:id="#+id/labelSubCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="SELECIONE A MARCA DO SEU VEÍCULO"
android:layout_marginTop="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<ListView
android:id="#+id/lvMarcaModelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#drawable/line" >
</ListView>
</LinearLayout>
</LinearLayout>
I have two Linear layouts in a xml file, one contains a textview follwed by list view. The next layout should be shown below the list view, which shows the description of selected item in listview as textview. Is this possible ? Below code doesn't show TextView01. In what other way i can do it, if it's not possible by this simple way?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="#string/hello_world"
android:textColor="#FFAABBFF" />
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp" >
</ListView>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/byebye_world"
android:textColor="#FFAEEEFF" />
</LinearLayout>
</LinearLayout>
try below code:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="hello_world"
android:textColor="#FFAABBFF" />
<ListView
android:id="#android:id/list"
android:layout_below="#+id/textView1"
anndroi:layout_above="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="byebye_world"
android:textColor="#FFAEEEFF" />
</LinearLayout>
</RelativeLayout>
you need to use layout_weight attribute for this. try this layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:orientation="vertical"
android:layout_weight="1"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="#string/hello_world"
android:textColor="#FFAABBFF" />
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:orientation="vertical"
android:layout_weight="2"
>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/byebye_world"
android:textColor="#FFAEEEFF" />
</LinearLayout>
</LinearLayout>
I have a Fragment layout that have also a ListView. I populate, this ListView with custom ArrayAdapter. Now, if I insert more items, I can't scrolling this list.
So I want to know how can I insert a vertical scrollbar to ListView.
This is the layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="800dp"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="830dp"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:id="#+id/layoutText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#id/layoutDate">
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
android:background="#color/green"
android:layout_marginTop="15dp"/>
<!--LIST OF AGENT-->
<LinearLayout
android:id="#+id/layoutAgent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_below="#id/layoutDate">
<TextView
android:id="#+id/labelListAgent"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:gravity="left|center"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:text="#string/agent"/>
<ListView
android:id="#+id/listOfAgent"
android:layout_width="240dp"
android:layout_height="120dp"
android:scrollbars="vertical"
android:layout_gravity="fill_vertical"
android:layout_alignParentTop="true">
</ListView>
</LinearLayout>
<TextView android:id="#+id/labelAgent"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:gravity="left|center"
android:paddingLeft="15dp"
android:hint="Insert agent"
android:clickable="true"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Add this to the xml of your ListView:
android:scrollbars="vertical"
Just checked your code. I think your problem could because you gave a fixed hight to your listview. Change android:layout_height="120dp" to
android:layout_height="wrap_content"
there is a scroollbar on listView by default.
you should set the height as android:layout_height="wrap_content" and remove the android:layout_gravity="fill_vertical"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:id="#+id/layoutText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
android:background="#android:color/holo_green_dark"
android:layout_marginTop="15dp"/>
<!--LIST OF AGENT-->
<LinearLayout
android:id="#+id/layoutAgent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/labelListAgent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="left|center"
android:paddingLeft="15dp"
android:paddingStart="15dp"
android:paddingEnd="15dp"
android:paddingTop="15dp"
android:text="agent"/>
<ListView
android:id="#+id/listOfAgent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5">
</ListView>
</LinearLayout>
<TextView android:id="#+id/labelAgent"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingStart="15dp"
android:paddingEnd="15dp"
android:gravity="left|center"
android:paddingLeft="15dp"
android:hint="Insert agent"
android:clickable="true"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
When in the main activity, there is a ScrollView, the other Scrollar do not works. Then the solution is to remove ScrollView in top of my Layout file, and the ListView scrollbar, works