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

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>

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>
Please approve answer if it will work for you. Thanks!

Related

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.

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

Text is not correctly displaying in a TextView

I'm making a design in android using simple LinearLayout I create a TextView inside CardView when I enter long text inside TextView it hides some of the text, why this is happening? Check below image
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/universal_padding"> <!-- 8dp -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="#dimen/card_profile_pic_width_height"
android:layout_height="#dimen/card_profile_pic_width_height"
app:srcCompat="#drawable/circular_photo" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="#dimen/badge_width_height"
android:layout_height="#dimen/badge_width_height"
android:layout_marginTop="10dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
app:srcCompat="#drawable/shap_circle_badge" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
android:textColor="#color/colorPrimaryText"
android:text="Azeem Haider" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text=" - 2d"/>
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose"
/>
</LinearLayout>
</LinearLayout>
Try this
<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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="96dp"
android:layout_height="96dp"
app:srcCompat="#drawable/kid" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
android:layout_marginTop="10dp"
app:srcCompat="#drawable/ic_online" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Azeem Haider"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - 2d" />
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose" />
</LinearLayout>
</LinearLayout>
OUTPUT

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 somewhere stupid mistake.
Tahnks for help guys :)
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>

layout in android studio

I get confused when it comes to layout in android.
I am trying to get a layout similar as picture below where the textfield is all the way to the right side and the text somehow align in the middle or so. can someone help me get the layout as the attached image?
layout image
also, can someone figure out what is the name of the text and size in the attached image. i like it and would like to use it in my app.
I appreciate if someone can post some xml code to get layout in the pic (link attached).
A simple example with two or 3 text and corresponding textfield align as the pic shows will be enough.
thanks
You can use this
<?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="match_parent"
android:orientation="vertical" >
<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:text="Description"
android:textColor="#000000" >
</TextView>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</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:text="Amount"
android:textColor="#000000" >
</TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</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:text="Amount"
android:textColor="#000000" >
</TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Help" />
</LinearLayout>
</LinearLayout>
I have provided here basic layout that contains first three rows of layout..
Please try this and add all your next entities in and let me know if you stuck somewhere..!!
<LinearLayout
android:id="#+id/linear_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:text="Description"
android:textAlignment="gravity"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_description"
android:orientation="horizontal"
android:weightSum="6">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="end"
android:text="Amount"
android:textAlignment="gravity"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/btn_star_big_off" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_tax"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_amount"
android:orientation="horizontal"
android:weightSum="6">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="end"
android:text="Tax"
android:textAlignment="gravity"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/btn_star_big_off" />
</LinearLayout>
Thanks.!!

Resources