android linearlayout not align right - android

I have a layout that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/menu_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackgroundFloating"
android:minWidth="600dp"
app:contentInsetStart="0dp"
android:elevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end">
<Button
android:id="#+id/confirm_button"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:text="Confirm"
android:textAllCaps="false" />
<Button
style="?android:attr/buttonBarStyle"
android:id="#+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:text="Reset"
android:textAllCaps="false" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/prefer_tags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
<FrameLayout
android:id="#+id/exclude_tags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
</LinearLayout>
The confirm button and the reset button are supposed to be on the right of the toolbar. However, they are only there unless there is something in the FrameLayout (either prefer_tags or exclude_tags). You can see from the images below:
How do I always keep my button on the right?

Try replacing
android:layout_width="match_parent"
android:gravity="end"
to
android:layout_width="wrap_content"
android:layout_gravity="end"

Related

overlapping a screen in android

In the below layout i have a text view named as scanning device.In that am displaying a device name But my device list was displaying above the screen .
can any one please help me how to scroll view should be inside the device list.while scrolling the screen it was displaying the list of the devices but it is displaying above the screen.
want to display inside a screen.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="#string/back"
android:textAllCaps="true"
android:textColor="#color/white"
android:visibility="invisible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:padding="10dp"
android:textStyle="bold"
android:text="#string/lamp_list"
android:textAllCaps="true"
android:textColor="#color/white" />
<TextView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableRight="#drawable/refresh"
android:gravity="right"
android:padding="10dp"
android:textAllCaps="true"
android:textColor="#color/white" />
<ProgressBar
android:id="#+id/scanningProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="#drawable/baground"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="#string/start_discovery"
android:textColor="#color/white"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
In the below layout connect textview was coming out of the layout.
device_item.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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="6dp"
android:src="#drawable/lamp" />
<TextView
android:id="#+id/deviceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:textColor="#color/white"
android:textSize="17sp"
tools:text="Solar Enviro SSL 2016" />
<TextView
android:id="#+id/connect"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:background="#drawable/rounded_red_view"
android:text="#string/connect"
android:paddingBottom="1dp"
android:paddingTop=".2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/white"
android:textSize="17sp" />
</LinearLayout>
change this things..
used both wrap_content. i hope you also remove default action bar.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Instead of CoordinatorLayout use linear layout.
if u r a beginner start coding with linear layout. It is easy to understand.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

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

Scrollview hiding the textview text in landscape mode

I am trying to use the scrollview to make the textview wrapped within it scrollable.
I am using the grid layout and am able to position the items as I need to, particularly the long text block, wrapped in a scroll view (the text under the big heading).
However, upon rotating , the long text block disappears completely and I have to keep scrolling it up to make it visible. I need it to be visible as expected when in landscape mode.
landscape mode, now visible after swiping up
This is my XML
<?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">
<include layout="#layout/toolbar" android:id="#+id/toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_marginTop="20dp"
android:id="#+id/articlesummaryimageview"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummaryheadingtextview"
android:layout_below="#id/articlesummaryimageview"
android:layout_centerHorizontal="true"
android:textSize="26dp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_marginTop="20dp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/articlesummaryscreenscrollview"
android:layout_below="#id/articlesummaryheadingtextview"
android:fillViewport="false"
android:layout_above="#+id/showfullarticlebutton"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummarytextview"
android:textSize="18dp"
android:textAlignment="center"
android:padding="5dp"
/>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/showfullarticlebutton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="18dp"
android:text="Full Article"
style="#style/AlertDialog.AppCompat.Light"
/>
</RelativeLayout>
Thank you
You're going to have to make your whole layout scrollable or come up with a different design. To make the whole layout scrollable, put the RelativeLayout inside the ScrollView and set the layout_height for the ScrollView to be wrap_content.
<?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:id="#+id/articlesummaryscreenscrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<include
layout="#layout/toolbar"
android:id="#+id/toolbar"
/>
<ImageView
android:id="#+id/articlesummaryimageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<TextView
android:id="#+id/articlesummaryheadingtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/articlesummaryimageview"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textAlignment="center"
android:textSize="26dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/articlesummarytextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textAlignment="center"
android:textSize="18dp"
android:layout_above="#+id/showfullarticlebutton"
android:layout_below="#id/articlesummaryheadingtextview"
/>
<Button
android:id="#+id/showfullarticlebutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Full Article"
android:textSize="18dp"
style="#style/AlertDialog.AppCompat.Light"
/>
</RelativeLayout>
If your business rules don't allow for the entire layout to be scrollable, what you can do is put your ScrollView as the first layout in the XML and adjust your other views layout_above and layout_below to that initial one (basically making that the view that is always shown and everything else adjust around it).
<?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"
>
<ScrollView
android:id="#+id/articlesummaryscreenscrollview"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_above="#+id/showfullarticlebutton"
android:fillViewport="false"
>
<TextView
android:id="#+id/articlesummarytextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textAlignment="center"
android:textSize="18dp"
/>
</ScrollView>
<TextView
android:id="#+id/articlesummaryheadingtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/articlesummaryscreenscrollview"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textAlignment="center"
android:textSize="26dp"
android:textStyle="bold"
/>
<ImageView
android:id="#+id/articlesummaryimageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/articlesummaryheadingtextview"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<Button
android:id="#+id/showfullarticlebutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Full Article"
android:textSize="18dp"
style="#style/AlertDialog.AppCompat.Light"
/>
</RelativeLayout>
1. Add RelativeLayout as a direct child of ScrollView and put TextView inside it.
2. Use attributge android:fillViewport="true" to ScrollView.
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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/toolbar" android:id="#+id/toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_marginTop="20dp"
android:id="#+id/articlesummaryimageview"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummaryheadingtextview"
android:layout_below="#id/articlesummaryimageview"
android:layout_centerHorizontal="true"
android:textSize="26dp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_marginTop="20dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/articlesummaryscreenscrollview"
android:layout_below="#id/articlesummaryheadingtextview"
android:fillViewport="true"
android:layout_above="#+id/showfullarticlebutton">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummarytextview"
android:textSize="18dp"
android:textAlignment="center"
android:padding="5dp"
android:text="this is a text"/>
</RelativeLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/showfullarticlebutton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="18dp"
android:text="Full Article"
style="#style/AlertDialog.AppCompat.Light" />
</RelativeLayout>

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.

EditText not focussing on touch

My EditText looks like:
<EditText
android:id="#+id/uuidInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:inputType="text"/>
However, when I run my app, the EditText does not get focus on touch I dont know why.
I have a layout file beacon_data_input.xml which is included inside activity_main.xml
Here is my input view beacon_data_input.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:id="#+id/inputLayout"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beacon UUID:"/>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="* "
android:textColor="#color/red" />
<EditText
android:id="#+id/uuidInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beacon Major:"/>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="* "
android:textColor="#color/red"/>
<EditText
android:id="#+id/majorInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beacon Minor:"/>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="* "
android:textColor="#color/red"/>
<EditText
android:id="#+id/minorInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:inputType="number"/>
</LinearLayout>
activity_main.xml includes the above layout as:
<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:orientation="vertical"
android:fitsSystemWindows="true">
<include layout="#layout/custom_toolbar" />
<include layout="#layout/beacon_data_input" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="56dp"
android:id="#+id/proximityRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"></android.support.v7.widget.RecyclerView>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedButton
android:gravity="center"
android:id="#+id/StartButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#292d2e"
android:textColor="#48c68f"
android:textSize="24sp"
android:layout_alignParentBottom="true"
android:text="Start"
/>
<LinearLayout
android:orientation="vertical"
android:id="#+id/imageLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</RelativeLayout>
Thanks in Advance.
Your EditText is not getting touch because in activity_main.xml file, its getting overlap by RecyclerView & LinearLayout..
Try to put it like following (Add your edittextLayout over of each layout):
<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:orientation="vertical"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="56dp"
android:id="#+id/proximityRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"></android.support.v7.widget.RecyclerView>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedButton
android:gravity="center"
android:id="#+id/StartButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#292d2e"
android:textColor="#48c68f"
android:textSize="24sp"
android:layout_alignParentBottom="true"
android:text="Start"
/>
<LinearLayout
android:orientation="vertical"
android:id="#+id/imageLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
<!--- Add them in last -->
<include layout="#layout/custom_toolbar" />
<include layout="#layout/beacon_data_input" />
</RelativeLayout>
or try after setting the visibility of that RecyclerView & RobotoCondensedButton's & LinearLayout's visibility GONE.
This Worked for me
android:windowSoftInputMode="adjustPan"
add this line in your menifest in your activity.

Categories

Resources