How show cardview as a dilouge while bluring the background - android

I have a card view with 2 radio buttons I want to show it as a dialogue
I want to achieve multiple things
Showing card view as a dialogue
blurring the background layout while showing the dialog
I have 2 radio buttons (only one is selectable) I want that after selecting one of them the dialogue will disappear but not immediately at least there should be a short delay so the user can see the selection of the radio button
Note:- If you want more references of the code please tell me I will
update the question as you can find I dint include the fragment_home
java file so the question doesn't get long and confusing
Here is the layout
sort_image.xml
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:backgroundTint="#color/grey"
app:cardCornerRadius="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:fontFamily="#font/roboto"
android:text="Sort by"
android:textAlignment="center"
android:textColor="#color/lite_grey"
android:textSize="25sp" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/divider_line_sort_by"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/sort_textView"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
android:backgroundTint="#color/lite_grey"
app:cardCornerRadius="50dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="#+id/latest_sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:fontFamily="#font/roboto"
android:text="Latest"
android:textAlignment="center"
android:textColor="#color/lite_grey"
android:textSize="25sp" />
<TextView
android:id="#+id/most_popular_sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/latest_sort_textView"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_marginStart="30dp"
android:layout_marginTop="25sp"
android:fontFamily="#font/roboto"
android:text="Most Popular"
android:textAlignment="center"
android:textColor="#color/lite_grey"
android:textSize="25sp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<RadioButton
android:id="#+id/latest_sort_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25sp" />
<RadioButton
android:id="#+id/most_popular_sort_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</RadioGroup>
</RelativeLayout>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
fragment_home.xml // This layout contains the text which I want that when pressed I open the dialogue and also this is the fragment/layout which I want to blur when showing the dialogue
Note:- only included the necessary code of this layout
<com.google.android.material.card.MaterialCardView
android:id="#+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_toStartOf="#id/divider_line"
android:backgroundTint="#color/black"
android:elevation="6dp"
android:paddingBottom="10dp"
android:textAlignment="center"
app:cardCornerRadius="10dp">
<TextView
android:id="#+id/sort_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="5dp"
android:fontFamily="#font/roboto"
android:text="#string/sort"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="17sp"
android:textStyle="bold" />
</com.google.android.material.card.MaterialCardView>

I think you need to use dialog fragment. You can read more about that in official documentation https://developer.android.com/guide/fragments/dialogs

Related

Hello friends how achieve bottom media controller layout?

Hello friends i am beginner in android i want know how to achieve this type layout the image which shown below please help me i trying achieve this type of layout
It is very simple layout FYI
It can be done with any type of parent layout Constraint, Relative and
even with Linear
I will share a Relative one example. Use your own drawables and assests.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:padding="4dp">
<TextView
android:id="#+id/textViewSongTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="24dp"
android:layout_marginEnd="10dp"
android:layout_toStartOf="#+id/buttonBackward"
android:ellipsize="end"
android:maxLines="1"
android:padding="2dp"
android:text="Song Name - [details]"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewArtistName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textViewSongTitle"
android:layout_alignParentStart="true"
android:layout_marginStart="24dp"
android:layout_marginEnd="10dp"
android:layout_toStartOf="#+id/buttonBackward"
android:padding="2dp"
android:text="Singer Name"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Button
android:id="#+id/buttonForward"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:text="F"
android:textColor="#android:color/white" />
<Button
android:id="#+id/buttonPlayAndStop"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_toStartOf="#id/buttonForward"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:text="PS"
android:textColor="#android:color/white" />
<Button
android:id="#+id/buttonBackward"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_toStartOf="#id/buttonPlayAndStop"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:text="B"
android:textColor="#android:color/white" />
</RelativeLayout>

Custom Spinner - how to?

I'm trying to create a view like this on Facebook application.
but all I've got is this
My boss says it's ugly. I've tried everything but I don't know which visual element is that, I don't know where Facebook gets their widgets for Android, they look so different or doesn't exist.
I made this way:
<RelativeLayout
android:id="#+id/layoutPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="22dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/enterMobileNumber">
<TextView
android:id="#+id/country_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="4dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="#string/select_your_country"
android:textColor="#9B9B9B"
android:textSize="22sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
app:srcCompat="#drawable/ic_sortdown_48px"
tools:ignore="ContentDescription" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/country_code"
android:background="#737373" />
</RelativeLayout>
There's any way I can get the proper design?
Use spinner
<RelativeLayout
android:id="#+id/layoutPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="22dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/enterMobileNumber">
<TextView
android:id="#+id/country_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="4dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="#string/select_your_country"
android:textColor="#9B9B9B"
android:textSize="22sp" />
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="#string/spinner_title"/>
</RelativeLayout>
For your referance https://www.tutorialspoint.com/android/android_spinner_control.htm

how to make android activity to fit in all size of mobile display's?

I have aligned it perfectly in the android studio but when I'm running it, it goes out of order, I have tried in a smartphone as well as in emulator but the result is same.is there any way I can make it display in mobile the same the way I see in the android studio?
The pic that I have uploaded shows that in android studio the display looks perfectly fine but after running its position changes.
this is the xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wm"
tools:context="sanal.gmail.android.PetCare.doctorassignment">
<ImageView
android:id="#+id/imageView9"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="36dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/petownerde" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="match_parent"
android:layout_height="38dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout6"
app:srcCompat="#drawable/pet" />
<EditText
android:id="#+id/editText10"
android:layout_width="213dp"
android:layout_height="142dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="472dp"
android:background="#drawable/button"
android:ems="10"
android:gravity="top|left"
android:hint="Type your message here"
android:inputType="textMultiLine"
android:lines="10"
android:maxLength="160"
android:maxLines="5"
android:minLines="6"
android:scrollbars="vertical"
android:singleLine="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.036"
tools:layout_editor_absoluteX="99dp" />
<Button
android:id="#+id/button5"
android:layout_width="88dp"
android:layout_height="44dp"
android:layout_marginBottom="60dp"
android:layout_marginEnd="162dp"
android:layout_marginLeft="161dp"
android:layout_marginRight="162dp"
android:layout_marginStart="161dp"
android:layout_marginTop="19dp"
android:background="#drawable/button1"
android:onClick="sendmessage"
android:text="SEND"
android:textColor="#F6F6F6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText10" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="168dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView11"
app:layout_constraintVertical_bias="0.049">
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="84dp"
android:layout_height="160dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Pet name :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Breed :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Colour :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView24"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Age :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView25"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gender :"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pet name"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="breed"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="colour"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="age"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="gender"
android:textColor="#F6F6F6"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="136dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="31dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/imageView11"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView9">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="79dp"
android:layout_height="126dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Name :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Email :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Contact : "
android:textSize="18sp" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address : "
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="email "
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="phone number"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="address"
android:textColor="#F6F6F6"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
`
Follow these two links You will get your answer. Its a time consuming approach but definitely you will learn a lot from these links.
http://developer.android.com/training/multiscreen/screensizes.html
http://developer.android.com/guide/practices/screens_support.html
Making fully responsive your android application to all screen sizes is not a very tough job but it requires good knowledge and experience of layouts and there XML properties.
use RelativeLayout instead of constraintLayout
and give the perfectly position of your views they cant change view your layout
use property of RelativeLayout -> below , above , toLeftOf , toRightOf
and set your other component
and also height and width all component not fixed given..
your requirement fixed size then given fixed otherwise use match_parent and wrap_content
one important things for your layout either you can use scrollview coz your edittext and button are mess ... OR your component size given small then not mess your layout
also you can fixed size or density used then use Dependency SDP and SSP
For android there are several ways to make it Compatible with all the devices.
You can use the ConstraintLayout for more responsive activity instead of LinearLayout.
Apart from that use more flexible and adaptive layout like "match_parent", "wrap_content" instead of hard coded values.
For example -
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:margin_top="5sp"
And so on. I hope this will solve your problem.
For more info related to this you can check this link

Keypad pushes a ListView upward [duplicate]

This question already has answers here:
Android: How do I prevent the soft keyboard from pushing my view up?
(28 answers)
Closed 5 years ago.
I am quite new in Android UI design so please bear with me.
In a relative layout I have a number of different controls -- TextView, ET, Button etc, and at the bottom part a ListView is populated. On the load of the activity when the focus is going to the first input field (Edit Text) the keypad pushes up the ListView and it overlaps the other fields.
Below is the layout 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"
android:background="#android:color/holo_orange_light"
tools:context="com.as.myexpense.AddExpenseAct"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="#+id/tvShowExpnDate"
android:layout_width="385dp"
android:layout_height="19dp"
android:allowUndo="true"
android:autoSizeTextType="uniform"
android:background="#color/colorAccent"
android:fontFamily="sans-serif"
android:foregroundTintMode="src_over"
android:text="Expense for the date"
android:textColor="#android:color/background_dark"
android:textSize="12sp"
android:textStyle="bold"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded,UnusedAttribute"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="7dp" />
<TextView
android:id="#+id/txtChangeExpenseDate"
android:layout_width="88dp"
android:layout_height="17dp"
android:background="#android:color/holo_green_light"
android:text="Change Date"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvShowExpnDate"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
android:layout_below="#+id/tvShowExpnDate"
android:layout_alignStart="#+id/etExpenseAmount" />
<TextView
android:id="#+id/tvAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/imgCategory"
android:layout_below="#+id/txtChangeExpenseDate"
android:text="Amount"
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="#+id/tvShowExpnDate"
tools:layout_editor_absoluteX="48dp" />
<TextView
android:id="#+id/tvExpenseCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/imgCategory"
android:layout_below="#+id/etExpenseAmount"
android:text="Choose category"
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="#+id/tvAmount"
tools:ignore="HardcodedText,MissingConstraints"
tools:layout_editor_absoluteX="48dp" />
<EditText
android:id="#+id/etExpenseAmount"
android:layout_width="125dp"
android:layout_height="40dp"
android:ems="8"
android:inputType="numberDecimal"
android:labelFor="#+id/etExpenseAmount"
app:layout_constraintLeft_toRightOf="#+id/tvAmount"
app:layout_constraintTop_toBottomOf="#+id/tvShowExpnDate"
app:srcCompat="#android:color/holo_orange_light"
android:layout_alignTop="#+id/tvAmount"
android:layout_toEndOf="#+id/imgCategory"
android:layout_marginStart="12dp" />
<ImageButton
android:id="#+id/imgCategory"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignStart="#+id/tvTotalExpense"
android:layout_below="#+id/tvExpenseCategory"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvExpenseCategory"
app:srcCompat="#android:color/holo_orange_light"
tools:ignore="ContentDescription" />
<EditText
android:id="#+id/etShortDescription"
android:layout_width="200dp"
android:layout_height="39dp"
android:layout_above="#+id/btnAddExpnToList"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#+id/tvExpenseCategory"
android:autoText="true"
android:ems="10"
android:hint="#string/short_description"
android:inputType="textPersonName"
android:maxLines="1"
app:layout_constraintLeft_toRightOf="#+id/imgCategory"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="Deprecated,LabelFor" />
<Button
android:id="#+id/btnAddExpnToList"
android:layout_width="118dp"
android:layout_height="50dp"
android:layout_alignBottom="#+id/floatingActionButton"
android:layout_alignParentStart="true"
android:text="#string/Add"
android:textColor="#android:color/background_dark"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etShortDescription" />
<Button
android:id="#+id/btnCancel"
android:layout_width="118dp"
android:layout_height="50dp"
android:layout_below="#+id/etShortDescription"
android:layout_marginStart="17dp"
android:layout_toEndOf="#+id/btnAddExpnToList"
android:text="#string/Cancel"
android:textColor="#android:color/background_dark"
android:visibility="invisible"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etShortDescription" />
<ListView
android:id="#+id/lvExpenses"
android:layout_width="387dp"
android:layout_height="312dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/tvTotalExpense"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="?attr/colorButtonNormal"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnAddExpnToList" />
<TextView
android:id="#+id/tvTotalExpense"
android:layout_width="288dp"
android:layout_height="20dp"
android:layout_above="#+id/lvExpenses"
android:layout_marginStart="10dp"
android:text="Total expense "
android:visibility="invisible"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnAddExpnToList"
tools:ignore="HardcodedText" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tvTotalExpense"
android:layout_alignEnd="#+id/etShortDescription"
android:layout_marginBottom="6dp"
android:clickable="true"
android:focusable="true"
app:srcCompat="#android:color/holo_orange_dark" />
<TextView
android:id="#+id/tvExpnCatDisplay"
android:layout_width="90dp"
android:layout_height="20dp"
android:layout_above="#+id/btnAddExpnToList"
android:layout_alignStart="#+id/imgCategory"
android:background="#00000000"
android:textColor="#color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp"
android:textStyle="normal|bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/spTxnType"
android:layout_below="#+id/tvShowExpnDate"
android:layout_marginTop="9dp"
android:text="#string/payment_type"
android:textSize="18sp" />
<Spinner
android:id="#+id/spTxnType"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_toEndOf="#+id/btnCancel"
android:entries="#array/txnType_name"
android:spinnerMode="dialog"
android:theme="#style/AlertDialog.AppCompat" />
</RelativeLayout>
Below are the screenshots:
On load of the screen
Expected view
"adjustResize"
The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan"
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
according to your comment, use following in your activity manifest

Android RelativeLayout working in LayoutEditor but breaking on device

For the TitleBar I have a RelativeLayout, which should display two buttons on the right side, and two TextViews on the left side. I got the layout code working in the Editor, but on the device it always breaks down.
On the image you can see a Screenshot from the Layout Editor and from the device (runs like this on multiple devices).
Here is the Layout Code I'm using:
- I know I just can dump in LinearLayouts, but this should be possible with RelativeLayout?
- I used the "toStartOf" properties because I don't want to overflow the icons with text if the text might be longer.
- Bonus Question: how can I center the two labels vertical, so that they are also centered if I only have a title and set the subtitle visibility to GONE
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/toolbar_right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="#dimen/default_content_padding"
android:background="#android:color/transparent"
tools:src="#drawable/account"/>
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/toolbar_left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="16dp"
android:layout_toStartOf="#id/toolbar_right_button"
android:background="#android:color/transparent"
tools:src="#drawable/ic_notifications"/>
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toStartOf="#id/toolbar_left_button"
android:fontFamily="#string/font_family_medium"
android:textAppearance="?android:textAppearanceMedium"
tools:text="Title "/>
<TextView
android:id="#+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignWithParentIfMissing="true"
android:layout_below="#id/toolbar_title"
android:textAppearance="?android:textAppearanceSmall"
tools:text="Subtitle"/>
</RelativeLayout>
A ConstraintLayout would solve your problem. It keeps your layout flat, and also centers your text layouts vertically (and maintains it even after you 'remove' the subtitle).
<android.support.constraint.ConstraintLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/toolbar_right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/default_content_padding"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="#drawable/account" />
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/toolbar_left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/default_content_padding"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="#+id/toolbar_right_button"
app:layout_constraintTop_toTopOf="parent"
tools:src="#drawable/ic_notifications" />
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#string/font_family_medium"
android:textAppearance="?android:textAppearanceMedium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="#id/toolbar_subtitle"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/toolbar_left_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Title " />
<TextView
android:id="#+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:textAppearance="?android:textAppearanceSmall"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar_title"
tools:text="Subtitle" />
</android.support.constraint.ConstraintLayout>
I have made it simple so it wont get messy:
<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="wrap_content"
android:orientation="vertical">
<ImageButton
android:id="#+id/imageButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
app:srcCompat="#android:drawable/ic_menu_compass" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignStart="#+id/imageButton"
android:layout_below="#+id/imageButton"
app:srcCompat="#android:drawable/btn_dialog" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton2"
android:layout_alignParentStart="true"
android:text="TextView" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:text="TextView" />
There are high chances that if You add a lot of elements and tools to the layout it will get messy, try to keep it simple and You will find what caused the problem.

Categories

Resources