Why does my button not showing in the layout? - android

I've been making a tabbed activity with a list view in it. I've been trying to put a button under the list view, but when i run on my phone, the button doesn't show up.
My Fragment layout
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="#+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/item_detected"
android:textColor="#fff" />
<TextView
android:id="#+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_data"
android:layout_below="#id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/colorRedPrimary"
android:text="#string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</FrameLayout>
My layout preview in my android studio
The layout when i run it on my phone (I'm using an Asus Zenfone 5)
I'm not sure where i did wrong, i actually have change the button into the floating button, but only half of the button shows in the layout. (Plus i can't scroll the layout)
Update
I have resolved it, the problem is in the tabbed activity layout.
I use a constraint layout as the parent, i've changed it to Relative layout and it works perfectly

Try this
change color according to you!
<FrameLayout 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"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="#+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="detected"
android:textColor="#fff" />
<TextView
android:id="#+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff"
android:layout_marginRight="7dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_data"
android:layout_below="#id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/colorPrimary"
android:text="helo"
android:textAllCaps="false"
android:textColor="#fff"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</FrameLayout>

Try this code..
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="#+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/item_detected"
android:textColor="#fff" />
<TextView
android:id="#+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_data"
android:layout_below="#id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/btn_register" />
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/colorAccent"
android:text="submit"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</RelativeLayout>

Try with this code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="#+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Items Detected"
android:textColor="#fff" />
<TextView
android:id="#+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<ListView
android:id="#+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/btn_register"
android:layout_below="#+id/rl_total_data"/>
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
android:text="Register"
android:textAllCaps="false"
android:textColor="#fff" />

Try this
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/item_detected"
android:textColor="#fff" />
<TextView
android:id="#+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_data"
android:layout_below="#id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="#+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/colorRedPrimary"
android:text="#string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>

This is because of the "match parent" attribute that is in a view above your button.Your button therefore is not shown because a view on top of it has been set to occupy all the space of the parent.
SEE BELOW CODE modification
<FrameLayout
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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="#+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/item_detected"
android:textColor="#fff" />
<TextView
android:id="#+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_data"
android:layout_below="#id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/colorRedPrimary"
android:text="#string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</FrameLayout>
You could try to use weightSum as explained in this post.What is android:weightSum in android, and how does it work?
It give much more control in division of your parent layout

Related

Add ScrollView with Linear and Relative Layout

Hello I am trying to add a ScrollView in my project.
The purpose is that I will be putting multiple CardViews in the middle of my project.
It is within a Relative Layout. With a Linear Layout on the top portion. But also having a BottomNavigation at the bottom. Which I would like for it to be fixed and not scrolling.
Here is the XML Code
<?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:orientation="vertical"
tools:context=".Bottom_Nav"
android:fillViewport="true"
android:background="#drawable/bg7">
<LinearLayout
android:id="#+id/titlemenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/pacifico_regular"
android:text="Menu"
android:textColor="#6E2C00"
android:textSize="50dp"
android:textStyle="bold"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/carterone_regular"
android:text="View Our Seelction!"
android:textColor="#6E2C00"
android:textSize="20dp"
android:textStyle="bold"
android:layout_gravity="center"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/titlemenu"
android:layout_above="#id/bottom_navigation">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<androidx.cardview.widget.CardView
android:id="#+id/hot"
android:layout_width="320dp"
android:layout_height="match_parent"
app:cardCornerRadius="15dp"
android:layout_marginTop="10dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EB984E"
android:padding="10dp">
<TextView
android:id="#+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:fontFamily="#font/carterone_regular"
android:text="Cold Drinks"
android:textColor="#6E2C00"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/t1"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/carterone_regular"
android:text="Cool Off With Our Cold Bevs!"
android:textStyle="bold" />
<ImageView
android:layout_width="116dp"
android:layout_height="82dp"
android:layout_alignParentRight="true"
android:layout_marginRight="-31dp"
android:maxHeight="200dp"
android:src="#drawable/coldbev" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<Button
android:id="#+id/coldbutton"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:backgroundTint="#6E2C00"
android:textColor="#color/white"
android:text="View Cold Drinks"
android:layout_gravity="center"/>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#EB984E"
app:itemIconTint="#6E2C00"
app:itemTextColor="#6E2C00"
app:menu="#menu/menu_navigation" />
</RelativeLayout>
As of right now it looks like this :
https://ibb.co/4JP6cPP
just put scrollView in root view
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:orientation="vertical"
tools:context=".Bottom_Nav"
android:fillViewport="true"
android:background="#drawable/bg7">
<LinearLayout
android:id="#+id/titlemenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/pacifico_regular"
android:text="Menu"
android:textColor="#6E2C00"
android:textSize="50dp"
android:textStyle="bold"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/carterone_regular"
android:text="View Our Seelction!"
android:textColor="#6E2C00"
android:textSize="20dp"
android:textStyle="bold"
android:layout_gravity="center"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/titlemenu"
android:layout_above="#id/bottom_navigation">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<androidx.cardview.widget.CardView
android:id="#+id/hot"
android:layout_width="320dp"
android:layout_height="match_parent"
app:cardCornerRadius="15dp"
android:layout_marginTop="10dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EB984E"
android:padding="10dp">
<TextView
android:id="#+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:fontFamily="#font/carterone_regular"
android:text="Cold Drinks"
android:textColor="#6E2C00"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/t1"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/carterone_regular"
android:text="Cool Off With Our Cold Bevs!"
android:textStyle="bold" />
<ImageView
android:layout_width="116dp"
android:layout_height="82dp"
android:layout_alignParentRight="true"
android:layout_marginRight="-31dp"
android:maxHeight="200dp"
android:src="#drawable/coldbev" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<Button
android:id="#+id/coldbutton"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:backgroundTint="#6E2C00"
android:textColor="#color/white"
android:text="View Cold Drinks"
android:layout_gravity="center"/>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#EB984E"
app:itemIconTint="#6E2C00"
app:itemTextColor="#6E2C00"
app:menu="#menu/menu_navigation" />
</ScrollView>

How to scroll an EditText to the very top of the layout?

So I have this layout with some ChipsInput inside a scrollview and I simply want these to go to the very top when the keyboard is activated
I've tried to change windowSoftInputMode to adjustPan and others but it does not make it to go to the very top, just doesn't cover it.
Here's my xml layout
<LinearLayout 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:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background1"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layoutImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/colorPrimary"
android:elevation="12dp"
android:orientation="horizontal"
android:padding="10dp"
tools:targetApi="lollipop">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
android:layout_weight="1"
android:fontFamily="#font/quattrocento"
android:gravity="left"
android:text="#string/profile"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#color/textColor1"
tools:ignore="RtlHardcoded" />
<ImageButton
android:id="#+id/btUpdate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#color/colorPrimary"
android:src="#drawable/arrow_right_icon" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:orientation="vertical"
tools:targetApi="o">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/quattrocento"
android:gravity="center"
android:text="#string/gallery"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#color/textColor2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="#+id/close1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_close"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"
android:visibility="invisible"/>
<ImageButton
android:id="#+id/add1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add"
android:background="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"/>
<ImageView
android:id="#+id/photo1"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginHorizontal="5dp"
android:background="#drawable/rounded_rect_primary_dark"
android:elevation="5dp"
android:scaleType="fitXY"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="#+id/close2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_close"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"
android:visibility="invisible"/>
<ImageButton
android:id="#+id/add2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add"
android:background="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"/>
<ImageView
android:id="#+id/photo2"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginHorizontal="5dp"
android:background="#drawable/rounded_rect_primary_dark"
android:elevation="5dp"
android:scaleType="fitXY" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="#+id/close3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_close"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"
android:visibility="invisible"/>
<ImageButton
android:id="#+id/add3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add"
android:background="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"/>
<ImageView
android:id="#+id/photo3"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginHorizontal="5dp"
android:background="#drawable/rounded_rect_primary_dark"
android:elevation="5dp"
android:scaleType="fitXY"/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="5dp"
android:background="#color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="#string/about_me"
android:textColor="#color/textColor2"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white">
<EditText
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#color/white"
android:focusable="true"
android:maxLength="500"
android:inputType="text"
android:importantForAutofill="no"
android:autofillHints="no"
tools:ignore="LabelFor" />
<TextView
android:id="#+id/caracCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="500"
android:textColor="#color/black"
android:textSize="16sp"
android:layout_gravity="end" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="#string/interest1"
android:textColor="#color/textColor2"
android:textSize="20sp"
android:layout_gravity="center"
android:gravity="center"/>
<Spinner
android:id="#+id/categories1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:background="#color/colorPrimary" />
</LinearLayout>
<com.pchmn.materialchips.ChipsInput
android:id="#+id/chipsInput1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:elevation="3dp"
android:focusable="false"
app:chip_deletable="true"
app:chip_hasAvatarIcon="false"
app:hint="#"
app:chip_backgroundColor="#color/colorPrimary"
app:chip_deleteIconColor="#color/black"
app:chip_labelColor="#color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="#string/interest2"
android:textColor="#color/textColor2"
android:textSize="20sp"
android:layout_gravity="center"
android:gravity="center"/>
<Spinner
android:id="#+id/categories2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:background="#color/colorPrimary" />
</LinearLayout>
<com.pchmn.materialchips.ChipsInput
android:id="#+id/chipsInput2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:elevation="3dp"
android:focusable="false"
app:chip_deletable="true"
app:chip_hasAvatarIcon="false"
app:hint="#"
app:chip_backgroundColor="#color/colorPrimary"
app:chip_deleteIconColor="#color/black"
app:chip_labelColor="#color/black" />
<Button
android:id="#+id/btLogout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="25dp"
android:background="#color/colorPrimary"
android:elevation="12dp"
android:fontFamily="#font/quattrocento"
android:text="#string/logout"
android:textSize="20sp"
android:onClick="logout"
tools:targetApi="lollipop"
android:textColor="#color/black"/>
</LinearLayout>
</ScrollView>
I simply need it to be sent to the very top of the layout so my filterable list will appear when the user start to type.
You can use CoordinatorLayout as your root and NestedScrolView in it .
CoordinatorLayout as root reacts to keyboard and scrolls your layout to the top of your phone with assistant of NestedScrollView which your NestedScrollView includes your layout code .
To put the issue into perspective view
CoordinaterLayout > NestedScrolView > yourLayout
Change your layout XMl like code below
<android.support.design.widget.CoordinatorLayout
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.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background1"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<!-- rest of your layout xml code-->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

How to adjust different height of cardview on tablet and android phone?

I am making an android app that has a cardview inside a recyclerview. Cardview looks good on tablet and takes 40% size of screen. When i run it on a 5" android device, cardview covers 80% of screen size. Please check the code below and suggest some solutions to correct layout that automatically fits itself according to the screen sizes.
MainLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="true"
android:layout_below="#+id/empty_view"
android:orientation="vertical">
<SearchView
android:id="#+id/searchbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:scrollbars="vertical"
android:clipToPadding="false"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load More"
android:id="#+id/btnLoad"
android:layout_gravity="center_horizontal"
android:layout_below="#+id/recyclerview"
android:background="#42a7f4" />
</LinearLayout>
</LinearLayout>
CardViewTemplate.xml
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_gravity="start"
android:layout_width="match_parent"
card_view:cardUseCompatPadding="true"
android:layout_height="500dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
card_view:contentPaddingLeft="5dp"
card_view:contentPaddingRight="5dp"
card_view:contentPaddingTop="5dp"
card_view:cardCornerRadius="0dp">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:id="#+id/greenBoxView"
android:background="#EBEFF2"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
>
<ImageView
android:layout_height="30dp"
android:layout_width="30dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:src="#drawable/lab"
android:layout_gravity="center_vertical"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yay! This is a Sample Title Text"
android:textColor="#002868"
android:textStyle="bold"
android:paddingRight="70dp"
android:paddingLeft="60dp"
android:textSize="25dp"
android:layout_gravity="center_vertical" />
<ImageView
android:layout_height="30dp"
android:layout_width="30dp"
android:layout_alignParentRight="true"
android:src="#drawable/lab"
android:layout_marginRight="8dp"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
<LinearLayout
android:layout_below="#id/greenBoxView"
android:layout_above="#+id/footer"
android:id="#+id/centeralPart"
android:paddingTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="20dp"
android:id="#+id/txtMaintitle" />
<TextView
android:textColor="#0080ff"
android:textSize="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtSecondTitle" />
<ListView
android:id="#+id/mainlist_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:divider="#null"
android:dividerHeight="0dp"/>
</LinearLayout>
<LinearLayout
android:id="#id/footer"
android:layout_height="80dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/btnOrder"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Order"
android:background="#00AF50"
android:textColor="#FFFFFF"
android:layout_marginRight="10dp" />
<Button
android:id="#+id/btnCompare"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Compare"
android:textColor="#FFFFFF"
android:background="#0071C1" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
This is what CardViewTemplate.xml should look like:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText,ContentDescription" >
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
card_view:cardCornerRadius="0dp"
card_view:cardUseCompatPadding="true"
card_view:contentPaddingLeft="5dp"
card_view:contentPaddingRight="5dp"
card_view:contentPaddingTop="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/greenBoxView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EBEFF2"
android:orientation="horizontal">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:src="#drawable/lab"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingEnd="70dp"
android:paddingStart="60dp"
android:text="Yay! This is a Sample Title Text"
android:textColor="#002868"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:src="#drawable/lab" />
</LinearLayout>
<LinearLayout
android:id="#+id/centeralPart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footer"
android:layout_below="#id/greenBoxView"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp">
<TextView
android:id="#+id/txtMaintitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="20sp" />
<TextView
android:id="#+id/txtSecondTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#0080ff"
android:textSize="20sp" />
<ListView
android:id="#+id/mainlist_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:dividerHeight="0dp" />
</LinearLayout>
<LinearLayout
android:id="#id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/btnOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:background="#00AF50"
android:text="Order"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/btnCompare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#0071C1"
android:text="Compare"
android:textColor="#FFFFFF" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
In case this does not fit with your idea, please provide a screenshot of an inflated item view or a drawing of the layout.

How to fit the tab above of the screen when scrolling the page?

I want to design the screen. layout, tab and grid view I want to scroll option. In scroll time, fix the tab on the header (Below of status bar) and grid view scroll to end of grid view content. In the bottom, I fixed bottom navigation bar.
This is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/layout_background"
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rlay_home_page_Tap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rlay_home_page_Tap1"
android:background="#color/layout_background">
<RelativeLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="185dp"
android:background="#drawable/main_header_selector"
android:gravity="bottom|center">
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/llay_home_bottom2"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_toEndOf="#+id/llay_home_bottom2" />
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_image"
android:layout_marginTop="10dp"
android:layout_toEndOf="#+id/img_fb_dp"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textColor="#000"
android:textSize="16dp" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:layout_marginTop="24dp"
android:src="#drawable/ic_profile" />
<TextView
android:id="#+id/amsc_txt_home_fbusername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView10"
android:gravity="center"
android:textColor="#fff"
android:textSize="16dp" />
<TextView
android:id="#+id/amsc_txt_home_All_ImgCount"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_above="#+id/textView10"
android:layout_marginBottom="60dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="125 \nPhotos"
android:textColor="#fff"
android:textSize="12dp" />
<TextView
android:id="#+id/amsc_txt_home_Fav_ImgCount"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_above="#+id/textView10"
android:layout_alignParentEnd="true"
android:layout_marginBottom="60dp"
android:layout_marginEnd="20dp"
android:gravity="center"
android:text="125 \nFavouite"
android:textColor="#fff"
android:textSize="12dp" />
</RelativeLayout>
<android.support.design.widget.TabLayout
android:id="#+id/simpleTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:gravity="center"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/tab_select_color"
app:tabTextColor="#color/black_text_color" />
<RelativeLayout
android:id="#+id/llay_home_grd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/simpleTabLayout"
android:layout_above="#+id/linearLayout8"
android:background="#color/layout_background"
android:orientation="vertical">
<GridView
android:id="#+id/grid_test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:background="#color/layout_background"
android:horizontalSpacing="2dp"
android:numColumns="3"
android:verticalSpacing="2dp" />
>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/linearLayout8"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:background="#android:color/white"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:background="#android:color/white"
android:orientation="horizontal">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation_home1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:background="#color/wight"
app:itemIconTint="#drawable/bottom_navigation_color_selector"
app:itemTextColor="#drawable/bottom_navigation_color_selector"
app:menu="#menu/my_navigation_home" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:background="#android:color/white"
android:orientation="horizontal"
android:visibility="gone">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation_home2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:background="#color/wight"
app:itemIconTint="#drawable/bottom_navigation_color_selector2"
app:itemTextColor="#drawable/bottom_navigation_color_selector2"
app:menu="#menu/my_navigation_home2" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/img_take_cam_but"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:onClick=""
android:background="#drawable/ic_capture"/>
</RelativeLayout>
</FrameLayout>
Above code , gridview only scrolling.How to scroll image type.
use appbarlayout and drawer layout for doing the tab part
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar/>
<android.support.design.widget.TabLayout/>
</android.support.design.widget.AppBarLayout>
<!---your--layout--here--->
</android.support.design.widget.CoordinatorLayout>

to avoid spaces at bottom while scrolling down in scrollview

when i am scrolling down then unnecessary spaces are coming.so pls help me and i am using a scrollView for this activity.This is my .xml file,pls see to it and suggest me what to do because when i am scrolling down that unnecessary space making my app disgusting.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tools:context="com.example.vishal.a4sa.rubber">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Rubber Bowl"
android:gravity="center"
android:textColor="#01118c"
android:padding="#dimen/activity_horizontal_margin"
android:textStyle="bold"
android:textSize="30dp"
android:id="#+id/tv"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/image"
android:background="#drawable/image1"
android:layout_below="#+id/textView5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="900dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:id="#+id/content"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/imageView"
android:layout_alignStart="#+id/imageView" />
</LinearLayout>
</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:orientation="vertical"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Rubber Bowl"
android:gravity="center"
android:textColor="#01118c"
android:padding="#dimen/activity_horizontal_margin"
android:textStyle="bold"
android:textSize="30dp"
android:id="#+id/tv"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/image"
android:background="#drawable/image1"
android:layout_below="#+id/textView5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:id="#+id/content"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/imageView"
android:layout_alignStart="#+id/imageView" />
</LinearLayout>
</ScrollView>

Categories

Resources