Output displays differently on a Specific Android Device - android

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

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>

Create an EditText with RadioButton in the right

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>

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.

Want to add a scroll view

When I'm trying to add ScrollView its giving me error that Scroll view can contain only a single child. So how to add a ScrollView ?
And also when I open my app in various phones all the phones gives different layouts. How do manage the look and feel of the app same for all mobile devices ?
Register.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="match_parent"
android:background="#0066CC"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/upImage"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView1"
android:layout_width="465dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.02"
android:layout_marginBottom="100dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="Tap to upload Profile Picture" />
<EditText
android:id="#+id/imName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:hint="Enter name of the Image"
android:ems="10" >
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="#+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textPassword" />
<Button
android:id="#+id/bRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
Yes ScrollView allow only single child
So put you parent LinearLayout inside ScrollView like below
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0066CC"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/upImage"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView1"
android:layout_width="465dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.02"
android:layout_marginBottom="100dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="Tap to upload Profile Picture" />
<EditText
android:id="#+id/imName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:hint="Enter name of the Image"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="#+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textPassword" />
<Button
android:id="#+id/bRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
</ScrollView>
Android only supports a single child inside a ScrollView. The simplest way is to enclose everything inside a LinearLayout and make it a child of a ScrollView.
If you however want to maintain the same look and feel throughout the application, try using a RelativeLayout instead of the LinearLayout as the child of the ScrollView.

Android widget not showing up on the emulator screen

I have added some widgets on activity_main.xml, a layout file for main.java in android. When I ran the program on emulator, the last widget is missing in the emulator screen. What will be the reason? How to rectify it?
Here by I am giving below the code for activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg1"
android:paddingBottom="50dp">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:src="#drawable/cmplnlogo"
android:id="#+id/imageViewLogo" />
<EditText
android:layout_marginTop="30dp"
android:layout_width="310dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:inputType="textEmailAddress"
android:hint="#string/signupUserHint"
android:textSize="15sp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextEmail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewEmailValidator" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextPwd" />
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupCfmPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextConfirmPwd" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewPwdValidator" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/signInHint"
android:onClick="GoToLogin"
android:textColor="#FFFFFF"
android:id="#+id/textViewSignin" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/edittextstyle"
android:text="#string/SignUp"
android:onClick="SignUp"
android:textColor="#FFFFFF"
android:id="#+id/buttonSignUp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_terms"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textViewServiceTerms" />
</LinearLayout>
</LinearLayout>
I solved the problem mentioned in the above question by adding scrollview widget. I added the scrollview widget in the layout file for which all widgets are not appearing on the emulator. Remember scrollview only suppors only one direct file.
I had many layouts inside the layout file that enclosed different widgets. I enclosed all the layouts with in one layout. And then, enclosed that layout with scrollview. I am giving the snippet.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/scroll">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:id="#+id/registerUserName"
android:paddingBottom="10dp"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/enterRegisterUserName"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</Scrollview>

Categories

Resources