Android Lollipop device does not show bottom buttons - android

I have made layout which has buttons at bottom part:
<FrameLayout 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="my.site.com.myapp.fragments.NewsFragment">
<!— TODO: Update blank fragment layout —>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/newsListView"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="48dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/linearLayout4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Events"
android:id="#+id/fromNewsToAllEventsButton"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fromNewsToAllSharesButton"
android:layout_weight="1"
android:text="Shares"
android:background="#android:color/holo_blue_dark"/>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
Android 4.1 able to show bottom buttons while Android 5.1 does not.
On the left side Android 5.1 on the right side Android 4.1.
Does Android 5.1 requires additional configurations on layouts? If it is feature of new versions, then it is bad feature.
The main problem is that If this layout is placed on Activity it shows buttons. However it fails to show in Fragment

<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="my.site.com.myapp.fragments.NewsFragment">
<ListView
android:id="#+id/newsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/buttonLayout" />
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="#+id/fromNewsToAllEventsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"
android:text="All Events" />
<Button
android:id="#+id/fromNewsToAllSharesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/holo_blue_dark"
android:text="Shares" />
</LinearLayout>
</RelativeLayout>

I have to fix your layout replace your xml with below code.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="my.site.com.myapp.fragments.NewsFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/linearLayout4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Events"
android:id="#+id/fromNewsToAllEventsButton"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fromNewsToAllSharesButton"
android:layout_weight="1"
android:text="Shares"
android:background="#android:color/holo_blue_dark"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/newsListView"
android:layout_alignParentTop="true"
android:layout_above="#id/linearLayout4"
android:layout_marginBottom="5dp"
/>
</RelativeLayout>
</FrameLayout>

<FrameLayout 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="my.site.com.myapp.fragments.NewsFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/newsListView"
android:layout_alignParentTop="true"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/linearLayout4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Events"
android:id="#+id/fromNewsToAllEventsButton"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fromNewsToAllSharesButton"
android:layout_weight="1"
android:text="Shares"
android:background="#android:color/holo_blue_dark"/>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
Here is my output :

Related

How place overlay imageview on two layouts?

I want to build the following screen which contains app logo, success/failure icon image, information message and ok button.
Here this the code. I am using linear layout to achieve this.
<LinearLayout
android:id="#+id/statusLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#android:color/white"
android:weightSum="2"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="#+id/statusTopRelativeLayout"
android:background="#android:color/holo_blue_bright"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:id="#+id/client_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/no_image_description"
android:src="#drawable/client_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/statusBottomRelativeLayout"
android:background="#android:color/holo_blue_light"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/statusText"
android:textSize="50sp"/>
<Button
android:id="#+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/statusText"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:clickable="true"
android:focusable="true"
android:onClick="goToHomeScreen"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:text="#string/ok"
android:textColor="#ffffff"
android:textSize="40sp"/>
</RelativeLayout>
How to place success/failure icon image on top of the two layouts?
You can use constraint to make it easy
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.support.constraint.Guideline
android:id="#+id/center"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/center"
android:background="#ffffff"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#id/center"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#00ffff"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ff8801"
app:layout_constraintTop_toTopOf="#id/center"
app:layout_constraintBottom_toBottomOf="#id/center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
Output:
Try this
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/nilu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:orientation="vertical"
android:paddingBottom="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
<LinearLayout
android:id="#+id/nilu2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/nilu"
android:layout_weight="1"
android:background="#color/colorAccent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#mipmap/ic_launcher_round" />
</RelativeLayout>
</RelativeLayout>
OUTPUT
Parent RelativeLayout
add child LinearLayout as fillParent and assign weightsum 2. add two
layouts with 1 weight each. (add individual implementation for each
layout according to your requirements.)
add second child in relative
layout as imageview/button for that good sign and set it center in
parent.
This will fix your problem

Custom row with circular ImageView and textview in android

I am trying to create a custom row for my RecyclerView. Here is my custom row layout:
<?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="180dp"
android:layout_margin="5dp"
android:background="#00000000">
<FrameLayout
android:id="#+id/customLevelLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/levelImage"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_above="#+id/gameText"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="#drawable/circular_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1"
android:textColor="#fff"
android:textSize="45sp" />
<TextView
android:id="#+id/gameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="#000"
tools:text="Tracing" />
</RelativeLayout>
<ProgressBar
android:id="#+id/gameProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:indeterminate="true"
android:padding="45dp"
android:visibility="gone" />
</FrameLayout>
<ImageView
android:id="#+id/lockImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/lock_background"
android:padding="45dp"
android:src="#drawable/lock"
android:visibility="gone" />
</RelativeLayout>
This is how it looks like:
The problem is, I have to define a predefined height of the custom row i.e 170dp currently. I am facing 2 problems because of this:
1) If I open the application in a small screen or a tablet device. The custom row is looking ugly i.e I loose the circular shape of the ImageView.
2) The text doesn't remain at the centre if there is a slight change in the layout.
Try this in your 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="wrap_content"
android:layout_margin="5dp"
android:background="#00000000">
<FrameLayout
android:id="#+id/customLevelLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/levelImage"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="#drawable/circular_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="1"
android:textColor="#fff"
android:textSize="45sp"/>
</RelativeLayout>
<TextView
android:id="#+id/gameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="#000"
tools:text="Tracing"/>
</LinearLayout>
<ProgressBar
android:id="#+id/gameProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:indeterminate="true"
android:padding="45dp"
android:visibility="gone"/>
</FrameLayout>
<ImageView
android:id="#+id/lockImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/lock_background"
android:padding="45dp"
android:src="#drawable/lock"
android:visibility="gone" />
</RelativeLayout>
Try This. You can use Linearlayout as root than for image and text use RelativeLayout
<?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="wrap_content"
android:layout_margin="5dp"
android:background="#00000000"
android:orientation="vertical">
<FrameLayout
android:id="#+id/customLevelLayout"
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:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/levelImage"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="#drawable/circular_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1"
android:textColor="#fff"
android:textSize="45sp" />
</RelativeLayout>
<TextView
android:id="#+id/gameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:gravity="center"
android:textColor="#000"
tools:text="Tracing" />
</LinearLayout>
<ProgressBar
android:id="#+id/gameProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:indeterminate="true"
android:padding="45dp"
android:visibility="gone" />
</FrameLayout>
<ImageView
android:id="#+id/lockImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/lock_background"
android:padding="45dp"
android:src="#drawable/lock"
android:visibility="gone" />
</LinearLayout>
Use constrain layout which helps you to set image like you want just by drag and drop and add constrain
For supporting multiple screen. First you have to go through this link
enter link description here
Once you fix first issue, second issue also will get fix

Multiple recyclerview issue

I am trying to create an XML layout for football teams statistics and add who scored the goal for each team on the side of the vertical red view
After some work i created this layout:
This is my layout xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:card_view="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:cardUseCompatPadding="true"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start">
<ImageView
android:id="#+id/image_team1"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:src="#drawable/placemahdi"
/>
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end">
<ImageView
android:id="#+id/image_team2"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:src="#drawable/placemahdi"/>
</LinearLayout>
<TextView
android:id="#+id/versus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_stadium"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=":"
android:textSize="25sp" />
<com.github.pavlospt.CircleView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:id="#+id/point1"
android:layout_height="35dp"
app:cv_titleText="2"
app:cv_titleSize="14sp"
android:layout_marginRight="10dp"
android:layout_toStartOf="#+id/versus"
android:layout_toLeftOf="#+id/versus"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:cv_titleColor="#color/white"
app:cv_subtitleText=""
app:cv_strokeColorValue="#color/colorGreen"
app:cv_backgroundColorValue="#color/yellow"
app:cv_fillColor="#color/yellow"
app:cv_fillRadius="0.9"
app:cv_strokeWidthSize="3"/>
<com.github.pavlospt.CircleView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:id="#+id/point2"
android:layout_height="35dp"
app:cv_titleText="2"
app:cv_titleSize="14sp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/versus"
android:layout_toRightOf="#+id/versus"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:cv_titleColor="#color/white"
app:cv_subtitleText=""
app:cv_strokeColorValue="#color/colorGreen"
app:cv_backgroundColorValue="#color/yellow"
app:cv_fillColor="#color/yellow"
app:cv_fillRadius="0.9"
app:cv_strokeWidthSize="3"/>
<TextView
android:id="#+id/team2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ahed2"
android:textAlignment="center"
android:textSize="10sp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/point2"
android:layout_alignStart="#+id/point2" />
<TextView
android:id="#+id/team1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:text="ahed2"
android:textAlignment="center"
android:textSize="10sp"
android:layout_marginTop="5dp"
android:layout_below="#+id/point1"
android:layout_alignLeft="#+id/point1"
android:layout_alignStart="#+id/point1" />
</RelativeLayout>
<View
android:layout_width="2dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:layout_marginTop="50sp"
android:background="#a40404" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center|bottom"
android:layout_gravity="bottom"
android:textSize="20sp"
/>
</android.support.v7.widget.CardView>
</ScrollView>
</LinearLayout>
And this is my layout inflater where i added a recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_post"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Here is an image i am following :
I just want to add the player who scored the goal with the football icon foreach side of the vertical red line.
Should i create two recyclerview?
Any suggestions please?
If you are using LinearLayout with weight property you can reslove this issue..
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_red_dark"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="49"/>
</LinearLayout>
try this..

advanced filtering in android

I have to create an application which shows some data in Recycler view and set up an advance filtring options. The main options to search should be listed in the left hand side and if an item is being selected, set of options which is specifying the range with check boxes should be displayed accordingly. I cant set this view using layouts please help me to do this.
here is the output I expect
enter image description here
please help me to do this thanks in advance
this is what i did
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jijoabraham.informe.search"
android:background="#ffffff">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="#FF00BCD4"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_filter"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#1d2643"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sales Report"
android:layout_gravity="center"
android:textSize="20sp"
android:textColor="#android:color/background_light" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layright"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/layleft"
android:layout_above="#+id/laybottom"
android:background="#ffffff"></LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_height="match_parent"
android:id="#+id/layleft"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="100dp"
android:gravity="center"
android:layout_above="#+id/laybottom"
android:background="#ffffff"
android:padding="5dp">
<Button
android:text="Date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dte_btn"
android:background="#color/colorPrimaryDark"
android:textColor="#ffffff"
android:onClick="onSelect"
android:layout_marginBottom="5dp" />
<Button
android:text="Branch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/branch_btn"
android:background="#color/colorPrimaryDark"
android:textColor="#ffffff"
android:onClick="onSelect"
android:padding="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<Button
android:text="Reports"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/reports_btn"
android:background="#color/colorPrimaryDark"
android:textColor="#ffffff"
android:onClick="onSelect"
android:padding="5dp"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foregroundGravity="bottom"
android:id="#+id/laybottom"
android:layout_alignParentBottom="true">
<Button
android:text="Clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_clear"
android:background="#color/colorPrimaryDark"
android:textColor="#ffffff"
android:padding="5dp" />
<Button
android:text="Apply Filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btn_filter"
android:layout_gravity="right"
android:gravity="center"
android:foregroundGravity="right"
android:background="#color/colorPrimaryDark"
android:textColor="#ffffff"
android:padding="5dp"
android:layout_marginLeft="10dp" />
</LinearLayout>
You can create this type of layouts with the help of fragments easily.
Create four different fragments:
FilterMenuFragment for your left most screen.
DateFilterFragment for your right side screen if date is selected.
AdmissionFilterFragment for your right side screen if Admission is selected.
RankFilterFragment for your right side screen if Rank is selected.
And in your Activity class you can handle the visibility of fragments accordingly.
Try below layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Clear" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Apply Filter" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottomLayout"
android:background="#android:color/holo_red_dark"
android:orientation="horizontal"
android:weightSum="1">
<RelativeLayout
android:id="#+id/leftLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_bright"
android:gravity="left"
android:layout_weight="0.60"/>
<RelativeLayout
android:id="#+id/rightLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:gravity="right"
android:background="#android:color/holo_green_dark" />
</LinearLayout>
</RelativeLayout>
And to handle click of Clear and Apply Button, create interface with two methods apply(data) and clear(data) and implement these methods in all the right side fragments.

Android XML Layout is not fitting for most of devices

I am working on a Android project in android studio. In main activity layout the layout doesn't fit for every smart phone. Please help me in this case.
Here is the XML code of main playout
<?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:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ml.microlion.development.fmmahanama.MainActivity"
tools:showIn="#layout/app_bar_main">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
app:srcCompat="#mipmap/fmmahanama_banner2"
android:id="#+id/imageView9"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:layout_height="wrap_content" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Play Stream"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_playstream"
android:layout_weight="0.51"
android:textAppearance="#style/TextAppearance.AppCompat.Widget.Button.Colored"
android:backgroundTint="?android:attr/colorPressedHighlight"
android:elevation="0dp" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/adbar_prev"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="66dp">
<Button
android:text="Go To Website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_website"
android:layout_weight="1" />
<Button
android:text="Feedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_feedback"
android:layout_weight="1" />
<Button
android:text="Share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_share"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In default Device in Editor i use Nexus 4. It is ok on editor. But when I run it in my galaxy j7 and galaxy dous 2 i can see that layout doesn't fit.

Categories

Resources