Create an EditText with RadioButton in the right - android

I'm creating an Activity which user can create a Question and where can create answers, so, from now I have 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"
android:id="#+id/viewBinary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/constraintAnswerTypes"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear_view_option_1_binary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<RadioButton
android:id="#+id/cb_answer1_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="16dp" />
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_1_binary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:hintTextAppearance="#style/TextLabel">
<EditText
android:id="#+id/et_option1_binary"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="#string/respuesta_1"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/cb_answer2_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="16dp" />
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_2_binary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:hintTextAppearance="#style/TextLabel">
<EditText
android:id="#+id/et_option2_binary"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="#string/respuesta_2"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
And the result is this one :
The problem that I'm having is if the answer that user types is too long he can not see it , so I'm thinking to do something like match_parent on the width so user has more space to write, but then I have this also :
And perhaps create 4 different lines for each answer is kinda ugly...
My initial question is, how do I create the first output to be match_parent like if there's only 2 answers, but then the thing is when I have the four answers, how do I print those EditText?
Edit
For the first option I want something like this, there 2 lines are the TextInputLayout with the EditTexts and the circle on the right is the RadioButton

Please check below code. It will solve your issue for both case, just need to handle visibility for alternate answers. If you face any issue then please let me know in comment section.
Use your own drawables and assets.
<?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"
android:id="#+id/viewBinary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linear_view_option_1_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_1_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option1_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 1"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer1_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_view_option_3_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="gone">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_3_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option3_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 3"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer3_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linear_view_option_2_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_2_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option2_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 2"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer2_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_view_option_4_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="gone">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_4_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option4_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 4"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer4_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
For Vertical layout:
<?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"
android:id="#+id/viewBinary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear_view_option_1_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_1_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option1_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 1"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer1_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_view_option_3_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_3_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option3_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 3"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer3_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_view_option_2_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_2_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option2_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 2"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer2_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_view_option_4_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input_option_4_binary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
app:hintTextAppearance="#style/Widget.Design.TextInputLayout">
<EditText
android:id="#+id/et_option4_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Resposta 4"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/cb_answer4_binary_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
Please approve answer if it will work for you. Thanks!

Try this
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerHorizontal="true" android:id="#+id/linear_view_option_1_binary">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_weight = 1
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:hintTextAppearance="#style/TextLabel"
android:id="#+id/txt_input_option_1_binary"
android:layout_marginBottom="8dp">
<EditText android:id="#+id/et_option1_binary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:hint="#string/respuesta_1"/>
</android.support.design.widget.TextInputLayout>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginBottom="8dp" android:id="#+id/cb_answer1_binary_option"/>
</LinearLayout>
Basically we are setting layoutweit to be equal 1 on the edit text (or textinput in your case) and the width to 0dp. This way Edittext will consume only the available space, not the whole width

<LinearLayout
android:id="#+id/linear_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/txt_input"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:hintTextAppearance="#style/TextLabel">
<EditText
android:id="#+id/edt_option"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textCapSentences" />
</android.support.design.widget.TextInputLayout>
<RadioButton
android:id="#+id/rb_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

Related

Android, My EditText wont respect its weight in Linear Layout

In order to make my view always visible even when the keyboard shows, I made a linear layout and gave every item a weigth. I made the TextViews uniform and gave them a minimum size:
app:autoSizeMinTextSize="8dp", app:autoSizeTextType="uniform"
as you can see below. However, when I click to edit the EditText, everything gets smaller but the EditText will not respect the weigth, even though it has the value 4, which should make it appear much more than the rest. Also, the little TextView disappear almost completely
What is happening?
<?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="match_parent"
android:orientation="vertical"
tools:context=".ChargeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6"
android:orientation="vertical">
<CheckBox
android:id="#+id/receiveCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="Receber valor automaticamente" />
<TextView
android:id="#+id/textViewValueToCharge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="#string/charge_hint_type_value_with_decimals"
app:autoSizeMinTextSize="8dp"
app:autoSizeTextType="uniform" />
<EditText
android:id="#+id/editTextValueToCharge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="4"
android:gravity="center"
android:inputType="number"
android:textSize="30sp" />
<TextView
android:id="#+id/textViewPaymentOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="#string/charge_label_choose_payment_action_below"
app:autoSizeMinTextSize="8dp"
app:autoSizeTextType="uniform" />
<Button
android:id="#+id/buttonCreditOnly"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="#28a745"
android:text="#string/charge_button_credit_only" />
<Button
android:id="#+id/buttonCreditWithInstallments"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="#28a745"
android:text="#string/charge_button_charge_credit_with_installments" />
<Button
android:id="#+id/buttonDebit"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="#28a745"
android:text="#string/charge_button_charge_debit" />
<TextView
android:id="#+id/textViewNumberOfInstallments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="#string/number_of_installments"
app:autoSizeMinTextSize="8dp"
app:autoSizeTextType="uniform" />
<Spinner
android:id="#+id/spinnerNumberOfInstallments"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:visibility="gone">
<TextView
android:id="#+id/textViewProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/start_connection_terminal"
android:visibility="gone" />
<TextView
android:id="#+id/textViewResponse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/start_transaction_status"
android:visibility="gone" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"
app:layout_constraintBottom_toTopOf="#+id/buttonAction"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="#+id/imageViewResponse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/icon_denied"
android:tint="#android:color/holo_red_dark"
android:visibility="gone" />
</LinearLayout>
<Button
android:id="#+id/buttonAction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#28a745"
android:text="#string/charge_button_pay_label"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Output displays differently on a Specific Android Device

I created a simple button and recyclerview on XML in android studio.
For some devices i've tried, the button and recyclerview show up normally.
However this device i mentioned is show up differently.
Here's a the picture.
Recycler View
Button
It supposed to be normal size and no text being cropped.
Has anyone ever find the solution for these matter?
[EDIT]
Here's the related XML code for the button
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dine In/Take Away"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:textColor="#color/Black"
android:textStyle="bold"/>
<Spinner
android:id="#+id/spDineIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:spinnerMode="dropdown"
android:entries="#array/array_dine_in"
android:prompt="#string/spinner_dine_in" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/etlTableNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginTop="10dp">
<EditText
android:id="#+id/etTableNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="Table Number" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/etlQtyCust"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginTop="10dp">
<EditText
android:id="#+id/etQtyCust"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="Customer Total" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/etlCustomerName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginTop="10dp">
<EditText
android:id="#+id/etCustomerName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Customer Name"
android:inputType="textPersonName" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<Button
android:id="#+id/btnNext"
android:layout_width="110dp"
android:layout_height="55dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:text="Save"
android:textStyle="bold"
android:textColor="#color/ButtonTextColor"
android:background="#drawable/mybutton"
/>
<Button
android:id="#+id/btnMerge"
android:layout_width="110dp"
android:layout_height="55dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:text="Save & Merge"
android:textStyle="bold"
android:textColor="#color/ButtonTextColor"
android:background="#drawable/mybutton"
/>
<Button
android:id="#+id/btnCancel"
android:layout_width="110dp"
android:layout_height="55dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:text="Cancel"
android:textStyle="bold"
android:textColor="#color/ButtonTextColor"
android:background="#drawable/mybutton"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
TIA
Change android:gravity="right" to android:gravity="center_vertical" in the linear layout containing the buttons

how do i avoid android textview overlapping with the edittext

<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/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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"
tools:context="com.example.salu.xyz.SurroundingsPropertyFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<TextView
android:id="#+id/textView77"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Property Surroundings:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textSize="20sp"/>
<EditText
android:id="#+id/editText55"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="textMultiLine"
app:layout_constraintBaseline_toBaselineOf="#+id/textView77"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView78"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Class Of Locality:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView77"
android:textSize="20sp"/>
<Spinner
android:id="#+id/spinner9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBaseline_toBaselineOf="#+id/textView78"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText55" />
<TextView
android:id="#+id/textView79"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Proximities to Civic Amenities:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView78"
android:textSize="20sp"/>
<EditText
android:id="#+id/editText57"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBaseline_toBaselineOf="#+id/textView79"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner9" />
<TextView
android:id="#+id/textView80"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Neighbourhood:"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView79"
android:textSize="20sp"/>
<EditText
android:id="#+id/editText58"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBaseline_toBaselineOf="#+id/textView80"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText57" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</ScrollView>
Hi, I'm new to Android Application Development, I am creating a form in Fragment which has both TextView and EditText and I was Testing it for 5-inch screens, but the TextViewand EditText got overlapped.
I tried widgets to resize them but the alignment looks bad once I go towards higher screen size.
Is there a way this can be rectified or avoided?
use linearlayout for forms and keep the parent layout to RelativeLayout. Do something like this and your form will be fine on every device:
<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/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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"
tools:context="com.example.salu.libravaluation.SurroundingsPropertyFragment">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="#+id/textView77"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Property Surroundings:"
android:textSize="20sp" />
<EditText
android:id="#+id/editText55"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll1"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="#+id/textView78"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Class Of Locality:"
android:textSize="20sp" />
<Spinner
android:id="#+id/spinner9"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll2"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="#+id/textView79"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center|start"
android:layout_height="match_parent"
android:text="Proximities to Civic Amenities:"
android:textSize="20sp" />
<EditText
android:id="#+id/editText57"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBaseline_toBaselineOf="#+id/textView79" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll3"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="#+id/textView80"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Neighbourhood:"
android:textSize="20sp" />
<EditText
android:id="#+id/editText58"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>
</RelativeLayout>
</ScrollView>

LinearLayout - 3 objects next to each other

This will be pretty easy question, but I tried so much answers in other topics and nothing helped :/
What I have and what I want:
My code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/spacing_medium">
<LinearLayout
android:id="#+id/lyt_fullname_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:minHeight="#dimen/spacing_xxlarge"
android:onClick="clickLayout"
android:orientation="horizontal">
<ImageView
android:layout_width="#dimen/spacing_mlarge"
android:layout_height="#dimen/spacing_mlarge"
android:layout_margin="#dimen/spacing_middle"
android:src="#drawable/ic_name_mountain_212121"
android:tint="#color/colorPrimaryBlack" />
<TextView
android:id="#+id/textView_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="5" />
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/fullname_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="250"
android:layout_margin="#dimen/spacing_medium"
android:hint="#string/placeholder_chillspot_name"
android:textSize="18sp"
android:text="sagdkojsgdfjiklnsagdikljsgdafnmkljsagdfmlskagdmgsdaůlksmdgklůsgdamlůksagdsdfztpkmtzrskoůltzersklůodmsljkdmgslkjdgmslkgsedmlgfůdekmgerlaskůmsgadflůsgm,aasgklů,"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
I tried align these object, layout weight and so on, but I am doing some mistake.
I just change some of your paddings and margins to see the result but the main point is to change the place of TextView and play with weights for ImageView TextView and TextInputLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/spacing_normal">
<LinearLayout
android:id="#+id/lyt_fullname_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:onClick="clickLayout"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="#dimen/spacing_normal"
app2:srcCompat="#drawable/ic_swap"
android:backgroundTint="#color/bb_darkBackgroundColor"
android:tint="#color/amber_50" />
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="0dp"
android:layout_weight="10"
android:layout_height="wrap_content">
<EditText
android:id="#+id/fullname_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_normal"
android:maxLength="250"
android:text="sagdkojsgdfjiklnsagdikljsgdafnmkljsagdfmlskagdmgsdaůlksmdgklůsgdamlůksagdsdfztpkmtzrskoůltzersklůodmsljkdmgslkjdgmslkgsedmlgfůdekmgerlaskůmsgadflůsgm,aasgklů,"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/textView_counter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_alignParentTop="true"
android:text="5" />
</LinearLayout>
</LinearLayout>
Try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/spacing_medium">
<LinearLayout
android:id="#+id/lyt_fullname_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:minHeight="#dimen/spacing_xxlarge"
android:onClick="clickLayout"
android:orientation="horizontal">
<ImageView
android:layout_width="#dimen/spacing_mlarge"
android:layout_height="#dimen/spacing_mlarge"
android:layout_margin="#dimen/spacing_middle"
android:src="#drawable/ic_name_mountain_212121"
android:tint="#color/colorPrimaryBlack" />
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/fullname_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="250"
android:layout_margin="#dimen/spacing_medium"
android:hint="#string/placeholder_chillspot_name"
android:textSize="18sp"
android:text="sagdkojsgdfjiklnsagdikljsgdafnmkljsagdfmlskagdmgsdaůlksmdgklůsgdamlůksagdsdfztpkmtzrskoůltzersklůodmsljkdmgslkjdgmslkgsedmlgfůdekmgerlaskůmsgadflůsgm,aasgklů,"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/textView_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="top"
android:text="5" />
</LinearLayout>

Android - Set custom dialog layout height to wrap_content

I am using a custom layout to show a dialog. Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/dialog_title_tv"
android:text="Dialog Title"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Country: "
android:padding="8dp"
/>
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:id="#+id/country_spinner"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select City: "
android:padding="8dp"
/>
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:id="#+id/city_spinner"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Area: "
android:padding="8dp"
/>
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:id="#+id/area_spinner"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
/>
</LinearLayout>
</LinearLayout>
It shows like this:
However, I want to set its height as WRAP_CONTENT. Currently, it's taking up the whole screen. How can I do this? What am I doing wrong? Thanks in advance
try this layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/dialog_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dialog Title"
android:textSize="20sp"
android:textStyle="bold" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Select Country: " />
<Spinner
android:id="#+id/country_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Select City: " />
<Spinner
android:id="#+id/city_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Select Area: " />
<Spinner
android:id="#+id/area_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/AddtoCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Done" />
</RelativeLayout>
</LinearLayout>
<?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="#1a000000"
android:layout_margin="16dp"
android:padding="16dp">
<TextView
android:id="#+id/dialog_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="My Dialog"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dialog_header"
android:layout_marginTop="8dp">
<android.support.design.widget.TextInputEditText
android:id="#+id/text_input_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:hint="Enter phone number"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/select_country_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Country:"
android:layout_toStartOf="#+id/country_spinner"
android:layout_alignBottom="#+id/country_spinner"
android:textSize="14sp"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"/>
<Spinner
android:id="#+id/country_spinner"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/text_input_layout"
android:layout_alignParentEnd="true"
android:layout_marginTop="8dp"/>
<TextView
android:id="#+id/select_city_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select City:"
android:layout_toStartOf="#+id/city_spinner"
android:layout_alignBottom="#+id/city_spinner"
android:textSize="14sp"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"/>
<Spinner
android:id="#+id/city_spinner"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:prompt="Select One"
android:layout_below="#+id/country_spinner"
android:layout_alignParentEnd="true"
android:layout_marginTop="8dp"/>
<TextView
android:id="#+id/select_area_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Area:"
android:layout_toStartOf="#+id/area_spinner"
android:layout_alignBottom="#+id/area_spinner"
android:textSize="14sp"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"/>
<Spinner
android:id="#+id/area_spinner"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:prompt="Select One"
android:layout_below="#+id/city_spinner"
android:layout_alignParentEnd="true"
android:layout_marginTop="8dp"/>
<TextView
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="done"
android:textAllCaps="true"
android:layout_below="#+id/area_spinner"
android:layout_alignParentEnd="true"
android:layout_marginTop="24dp"
android:textSize="14sp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textColor="#00f"/>
<TextView
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="cancel"
android:textAllCaps="true"
android:layout_below="#+id/area_spinner"
android:layout_toStartOf="#+id/done"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:textSize="14sp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textColor="#00f"/>
</RelativeLayout>
Just copy paste the above XML code into your custom dialog layout.
Though you have already marked an answer as correct, I am posting this
because of the following reasons
It has no nesting of views, which will increase the efficiency of your code.
It follows the Android Design Guidelines of building a Dialog Box
I feel, in stack overflow, providing an optimal solution instead of correcting bugs in existing solution is much more important.
P.S: This is a non scroll view version of the dialog box. Since the
content is less. Please comment if you need scrollable version too. It
will have slightly different implementation which in turn will have
slightly different output.
You may want to try these:
Set android:layout_weight="1" inside your ScrollView
Set android:layout_height to some static height (in dp).
Change parent from LinearLayout to RelativeLayout.

Categories

Resources