My listview works well in virtual device. When I tried to test on real device, my listview not showing anything.
Here my list xml code.
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:background="#FAFAFA" tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lacci_list"
android:divider="#E8E8E8"
android:dividerHeight="1dp"/>
</RelativeLayout>
Here my row xml code:
<?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:background="#FAFAFA">
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="lacci"
android:id="#+id/lacci_row"
android:textSize="16sp"
android:textColor="#000"
android:layout_gravity="center_horizontal"
android:gravity="left|center_vertical"/>
</LinearLayout>
Related
I´m trying to make a scrollview but it is getting itself applied on the 2 lists I have in the LinearLayout, scrollview child. I want to be able to scroll, vertically, through the entire layout, but it only lets me scroll on the lists. What did I do wrong and could it be fixed?
Thanks in advance
content_habilitacoes.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.luis.trabindividual.HabilitacoesActivity"
tools:showIn="#layout/app_bar_habilitacoes">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/content_habilitacoes_titulo_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_habilitacoes_titulo_1"
style="#style/contentMainTitle"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ListaHab1"/>
<TextView
android:id="#+id/content_habilitacoes_titulo_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_habilitacoes_titulo_2"
style="#style/contentMainTitle"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ListaHab2"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
How it is being displayed:
I'm trying to add a toolbar in my xml files.
So I made toolbar.xml and I need to include it in upload.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.sk.mf.Upload"
android:background="#fff">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageToUpload"
android:layout_gravity="center_horizontal"
android:layout_width="150dp"
android:layout_height="150dp" />
<EditText
android:id="#+id/etUploadName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/bUploadImage"
android:text="Upload Image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
the problem is, anywhere I place it I had error like:
scrollview can host only one direct child (inside scrollview)
multiple root tags (after scrollview)
...
my question here is, where and how can I put the code below in the xml above?
<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">
<include android:id="#+id/toolbar" layout="#layout/toolbar"></include>
</RelativeLayout>
try this : wrap your layout in LinearLayout and the toolbar tag
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"></include>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:padding="10dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.sk.mf.Upload">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageToUpload"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal" />
<EditText
android:id="#+id/etUploadName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/bUploadImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Upload Image" />
</LinearLayout>
</ScrollView>
</LinearLayout>
simple question ,
why my Card View have long Margin bettween other list ?
this is my code
card.xml
`
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:scaleType="fitXY"
android:id="#+id/imagePasar" />
<TextView
style="#style/Base.TextAppearance.AppCompat.Body1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Material Design is stunning!!!"
android:id="#+id/namaPasar" />
</LinearLayout>
</android.support.v7.widget.CardView>
`
and heres the mainLayout that used in the mainActivity
MainLayout
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="id.web.gosoft.pasarwiki.MainActivity"
tools:showIn="#layout/app_bar_main">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RecViewListPasar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
It is because of android:scaleType="fitXY". This will scale your image using Fill. Read this guide for more help.
I am trying to make ListView full-screen size, but every time in my scroll view I can see just one item from ListView.
There is my code:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<!-- progress -->
<ProgressBar android:id="#+id/login_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:visibility="gone" />
<ScrollView android:id="#+id/main_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="#+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
That's how it looks:
How do I want to make it look:
I can't achieve this without harcode height of ListView.
To put ListView inside ScrollView very bad idea. Try to not do it
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
it because in your top LinearLayout use padding. so, you can delete the all padding
so, it should be like this :
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<!-- progress -->
<ProgressBar android:id="#+id/login_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:visibility="gone" />
<ScrollView android:id="#+id/main_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="#+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</ScrollView>
I am using a spinner for drop down in my android app. But, problem is when user scrolls down, the spinner moves up and becomes invisible. I want to fix the spinner at the top of the page so that user can easily select the page.
Here with Scrollbar:
On scrolling down it disappears:
Edit 1: Layout file:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/backgroundColor"
xmlns:android="http://schemas.android.com/apk/res/android">
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scrollbars="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.shiza.dailyquranverses.Quran">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/selectChapter">
</Spinner>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/verse"
android:maxLines = "2000"
android:textSize="#dimen/verse_font_chapter"
android:text="Hello from Quran"
android:scrollbars="vertical"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical">
<Spinner
android:id="#+id/selectChapter"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ScrollView
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scrollbars="vertical"
tools:context="com.example.shiza.dailyquranverses.Quran">
<TextView
android:id="#+id/verse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2000"
android:scrollbars="vertical"
android:text="Hello from Quran" />
</LinearLayout>
</ScrollView>
</LinearLayout>