my problem is that my text is cut :/
and I would like something like
here is my edittext :
<?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">
<android.support.v7.widget.Toolbar
android:id="#+id/tool_bar_messa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f4f4f4"
android:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/Contact"
android:textColor="#000"
android:textSize="30sp"
android:theme="#android:style/DeviceDefault.ButtonBar.AlertDialog"
android:id="#+id/tv_toolbar"
android:singleLine="true"
android:ellipsize="end" />
<TextView
android:id="#+id/tvDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:singleLine="false"
android:text="#string/Details"
android:textColor="#3391e4"
android:textSize="20sp"
android:theme="#android:style/DeviceDefault.ButtonBar.AlertDialog" />
</android.support.v7.widget.Toolbar>
<ListView
android:id="#+id/lv_message"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:divider="#null"
android:dividerHeight="0dp"
android:stackFromBottom="false"
android:windowSoftInputMode="adjustResize" />
<RelativeLayout
android:id="#+id/layout_send"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="46dp">
<EditText
android:id="#+id/Et_message"
android:layout_width="294dp"
android:hint="#string/sms_mms"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="bottom"
android:inputType="textMultiLine|textCapSentences"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:textCursorDrawable="#null" />
<ImageButton
android:id="#+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/Et_message"
android:layout_toEndOf="#+id/Et_message"
android:layout_toRightOf="#+id/Et_message"
android:background="#00ffffff"
android:src="#drawable/btnsend" />
</RelativeLayout>
</LinearLayout>
and this is before open keyboard then photo I modify some thing about my listview to start the bottom and resize it when keyboard is open stuff like that, maybe it's the problem ?
just remove android:lines="2" and it solve. and you want all the lines to show then also remove android:maxLines="3".
<EditText
android:id="#+id/Et_message"
android:layout_width="294dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="bottom"
android:hint="Type here"
android:inputType="textMultiLine|textCapSentences"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:maxLines="3"
android:textCursorDrawable="#null" />
this is working correctly.
Related
I know this is common to ask but I'm having a trouble on how can I place the change password button beside edit button like the example image below, I tried app:layout_constraintLeft_toLeftOf="id" but it doesn't work, Is there anyway how can I manage in layout, I've keep searching till yet not found the answer, need help
**activity_main.xml **
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".EditProfile">
<ScrollView
android:id="#+id/scrolView_account"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/linear_account"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="50dp"
android:background="#color/primary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="10dp"
android:id="#+id/txtProfileDetails"
android:text="Profile Details"
android:textStyle="bold" />
<Button
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
app:layout_constraintLeft_toLeftOf="parent"
android:padding="10dp"
android:layout_marginRight="10dp"
android:id="#+id/editProfile"
android:drawableLeft="#drawable/ic_edit"
android:textStyle="bold" />
<Button
android:layout_width="205dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
app:layout_constraintLeft_toLeftOf="parent"
android:padding="10dp"
android:layout_marginRight="10dp"
android:id="#+id/editPassword"
android:text="Change Password"
android:textStyle="bold" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/cc_idno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:helperText="Mandatory"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
app:helperTextTextColor="#color/validation"
app:startIconDrawable="#drawable/ic_series"
android:layout_below="#+id/txtProfileDetails"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ID number"
android:id="#+id/edt_idno"
android:inputType="text"
android:layout_below="#id/edtFirstname"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageview_account_profile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/user_logo"
app:civ_border_color="#FFFFFF"
app:civ_border_width="2dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/imageview_account_profile"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Wrap your both the concerned buttons inside a linearlayout and it will work. with horizontal orientation .
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right">
<Button
android:id="#+id/editPassword"
android:layout_width="205dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:padding="10dp"
android:text="Change Password"
android:textStyle="bold"
/>
<Button
android:id="#+id/editProfile"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:padding="10dp"
android:textStyle="bold"
/>
</LinearLayout>
I want to create a view like this.
The problem is, that when the TextView size is bigger, it looks like this.
So it overlaps "View all (35)" TextView. How to prevent the overlapping? The ImageView should be right of TextView, but it has not to overlap "View all (35)". I think you understand. Thank you.
Here's the xml file.
<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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:fontFamily="#font/montserrat_semi_bold"
android:maxLines="1"
android:layout_alignParentStart="true"
android:textColor="#color/colorTextDark"
android:textSize="#dimen/text_extra_large"
tools:text="Birthday" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:layout_toEndOf="#+id/textView"
android:src="#drawable/wishlist_public" />
<TextView
android:id="#+id/textViewAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:fontFamily="#font/montserrat_semi_bold"
android:text="View all (35)"
android:layout_alignParentEnd="true"
android:textColor="#color/colorTextPrimary"
android:textSize="#dimen/text_small" />
</RelativeLayout>
Try to put your imageView to textView's drawableEnd property, after put it in nested linear layout and give to it a weight.
<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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/imageView"
android:layout_marginStart="16dp"
android:maxLines="1"
android:gravity="start|center"
android:textSize="#dimen/text_extra_large"
android:ellipsize="end"
android:text="Your text here" />
<Space
android:layout_width="match_parent"
android:layout_height="match_parent">
</Space>
</LinearLayout>
<TextView
android:id="#+id/textViewAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:gravity="end"
android:layout_gravity="center_vertical"
android:text="View All"
android:textSize="#dimen/text_small" />
</LinearLayout>
Try this(Please add some of your dimens property that i remove because i didn't had them) :
<?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:orientation="horizontal"
android:paddingTop="10dp"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:maxLines="1"
android:textSize="20dp"
tools:text="Birthdayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:layout_toRightOf="#id/textView"
android:src="#drawable/wishlist_public"
/>
</LinearLayout>
<TextView
android:id="#+id/textViewAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="2"
android:text="View all (35)"
android:textSize="20dp" />
</LinearLayout>
I think you can use Linearlayout to achieve something like that I use to write this code and I think it can help you achieve this layout design
<?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:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Birthdayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
android:layout_weight="1"
android:textSize="20sp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#111"
android:layout_marginStart="10dp" />
</LinearLayout>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View All(35)"
android:textSize="20sp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"/>
</LinearLayout>
After that, you will get something like that
Click here to view image
Try to use ContraintLayout and use Barrier constraint or Guidline constraint to achiever you desired layout
I have fixed using guideline contraint
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="16dp">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="24sp"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintHorizontal_bias="0.095"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.005"
tools:text="Birthday" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_adb_black_24dp"
app:layout_constraintBottom_toBottomOf="#+id/textViewAll"
app:layout_constraintEnd_toStartOf="#+id/textViewAll"
app:layout_constraintHorizontal_bias="0.13"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/textViewAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="View all (35)"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="333dp" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.62" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am trying to create a setting screen, below is the code and preview in Android Studio.
It has a couple of issues. The CardView with the scrollView layout is not working as it should
What I want is, my CardView to be adjusted in the middle of userDetailsLayout and logoutBtn with the spacing of #dimen/_20sdp. But it can be seen that its stretching all the way to logoutBtn,
If I use a small screen mobile, the CardView, also starts overlapping userDetailsLayout
It's like, its making CardView fixed size instead of variable-sized based on space. What should I do?
android:layout_margin="#dimen/_20sdp"
app:layout_constraintTop_toBottomOf="#+id/userDetailsLayout"
app:layout_constraintBottom_toTopOf="#+id/logoutBtn"
app:layout_constraintRight_toRightOf="parent"
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/forgot_bg_color"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:id="#+id/topBar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
app:contentInsetStart="0dp"
android:elevation="5dp"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/_100sdp"
android:background="#android:color/white"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_marginBottom="#dimen/_5sdp"
android:layout_marginRight="#dimen/_10sdp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="#dimen/_35sdp"
android:layout_height="#dimen/_35sdp"
android:src="#drawable/down_arrow"
android:scaleType="centerInside"
android:rotation="90"
android:layout_marginBottom="-10dp"
android:layout_above="#+id/inboxBtn"
android:id="#+id/backBtn"
/>
<TextView
android:layout_toRightOf="#+id/backBtn"
android:fontFamily="#font/montserrat_bold"
android:layout_above="#+id/inboxBtn"
android:gravity="bottom"
android:textSize="#dimen/_16sdp"
android:drawablePadding="#dimen/_8sdp"
android:text="#string/action_settings"
android:textColor="#color/text_gray"
android:id="#+id/homeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/inboxBtn"
android:fontFamily="#font/montserrat_medium"
android:layout_alignParentBottom="true"
android:textSize="#dimen/_14sdp"
android:gravity="center"
android:drawablePadding="#dimen/_8sdp"
android:textColor="#color/text_gray"
android:layout_width="wrap_content"
android:layout_height="#dimen/_35sdp"
/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<RelativeLayout
android:id="#+id/userDetailsLayout"
android:paddingLeft="#dimen/_20sdp"
android:paddingRight="#dimen/_20sdp"
app:layout_constraintTop_toBottomOf="#+id/topBar"
android:layout_width="match_parent"
android:layout_height="#dimen/_100sdp"
>
<androidx.cardview.widget.CardView
android:id="#+id/userLayout"
android:layout_centerVertical="true"
app:cardElevation="5dp"
app:cardCornerRadius="#dimen/_35sdp"
android:layout_width="#dimen/_70sdp"
android:layout_height="#dimen/_70sdp"
>
<ImageView
android:id="#+id/userDp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.cardview.widget.CardView>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_toRightOf="#+id/userLayout"
android:layout_marginLeft="#dimen/_10sdp"
>
<TextView
android:fontFamily="#font/montserrat_bold"
android:textSize="#dimen/_16sdp"
android:text="#string/action_settings"
android:textColor="#color/text_gray"
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/action_settings"
android:textColor="#color/text_gray"
android:id="#+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
<androidx.cardview.widget.CardView
android:layout_margin="#dimen/_20sdp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userDetailsLayout"
app:layout_constraintBottom_toTopOf="#+id/logoutBtn"
android:layout_width="match_parent"
app:cardCornerRadius="#dimen/_10sdp"
app:cardElevation="0dp"
android:layout_height="wrap_content"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
>
<TextView
android:layout_marginLeft="#dimen/_5sdp"
android:layout_centerVertical="true"
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/notifications"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Switch android:layout_width="wrap_content"
android:layout_marginRight="#dimen/_5sdp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
>
<TextView
android:layout_marginLeft="#dimen/_5sdp"
android:layout_centerVertical="true"
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/manage_address"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView android:layout_width="wrap_content"
android:layout_marginRight="#dimen/_5sdp"
android:layout_height="wrap_content"
android:src="#drawable/right_arrow_small"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
>
<TextView
android:layout_marginLeft="#dimen/_5sdp"
android:layout_centerVertical="true"
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/about"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView android:layout_width="wrap_content"
android:layout_marginRight="#dimen/_5sdp"
android:layout_height="wrap_content"
android:src="#drawable/right_arrow_small"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
>
<TextView
android:layout_marginLeft="#dimen/_5sdp"
android:layout_centerVertical="true"
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/support"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView android:layout_width="wrap_content"
android:layout_marginRight="#dimen/_5sdp"
android:layout_height="wrap_content"
android:src="#drawable/right_arrow_small"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
>
<TextView
android:layout_marginLeft="#dimen/_5sdp"
android:layout_centerVertical="true"
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/terms"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView android:layout_width="wrap_content"
android:layout_marginRight="#dimen/_5sdp"
android:layout_height="wrap_content"
android:src="#drawable/right_arrow_small"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
>
<TextView
android:layout_marginLeft="#dimen/_5sdp"
android:layout_centerVertical="true"
android:fontFamily="#font/montserrat_regular"
android:textSize="#dimen/_12sdp"
android:text="#string/privacy"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView android:layout_width="wrap_content"
android:layout_marginRight="#dimen/_5sdp"
android:layout_height="wrap_content"
android:src="#drawable/right_arrow_small"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray"
/>
</LinearLayout>
</ScrollView>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/logoutBtn"
android:fontFamily="#font/montserrat_bold"
android:gravity="center"
android:layout_marginRight="#dimen/_20sdp"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginBottom="#dimen/_20sdp"
android:layout_width="match_parent"
android:layout_height="#dimen/_40sdp"
android:textColor="#android:color/white"
android:text="#string/logout"
android:textSize="#dimen/_14sdp"
android:background="#drawable/logout_bg"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Not 100% sure what you mean, but from the code I would suggest you to change:
android:layout_width="0dp"
android:layout_height="0dp"
when you specify height and width constraints on the view. Otherwise the constraints won't work. And btw. dont use so many nested layouts inside your constraintlayout. Every single layout will need a complete new measure and render process which slow down your app a lot. Please also look at Guidelines and ConstraintAspectRatio.
The issue is that the logoutBtn is within the same parent as your CardView. They both have
android:layout_margin="#dimen/_20sdp"
That's why they have the same width, they both align right and left to the parent and have the same about of margin. So if you want it to be 20dp from the CardView you either want to nest the logoutBtn in the cardview or simply make the logoutBtn have 40dp
<TextView
android:id="#+id/logoutBtn"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="20dp"
android:background="#color/error_red"
android:gravity="center"
android:text="string/logout"
android:textColor="#android:color/white"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
My layout contains three buttons, one EditText field and one button. I want to place the three buttons in one row, but in the center (horizontal) of the screen. The EditText field should be below the buttons and below the EditText field, there should be one button.
Here is my layout:
<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="#color/blueAct"
android:orientation="vertical"
android:paddingBottom="100.0dip"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip"
android:paddingTop="100.0dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="4.0dip"
android:paddingLeft="100.0dip"
android:paddingRight="100.0dip"
android:paddingTop="5.0dip" >
<ImageButton
android:id="#+id/buttonGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4.0dip"
android:background="#drawable/green_button"
android:contentDescription="#string/green" />
<ImageButton
android:id="#+id/buttonRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4.0dip"
android:background="#drawable/red_button"
android:contentDescription="#string/red" />
<ImageButton
android:id="#+id/buttonBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4.0dip"
android:background="#drawable/blue_button"
android:contentDescription="#string/blue" />
</LinearLayout>
<EditText
android:id="#+id/phone_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/phone_code"
android:paddingTop="100.0dip"
android:textColor="#color/white"
android:textColorHint="#color/white" >
<requestFocus />
</EditText>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#color/orangeAct"
android:onClick="searchUsers"
android:paddingTop="100.0dip"
android:text="#string/button_go"
android:textColor="#color/white" />
</LinearLayout>
Now the problem is, that the three buttons are not in the center if the user changes from portrait to landscape mode.
How is it possible to make this 'responsive', without creating a separate layout file for landscape mode?
Any help would be greatly appreciated.
Don't use padding on your horizontal LinearLayout to center the views. Instead you can add views before and after that expand to fill the remaining space.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="#+id/buttonGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<ImageButton
android:id="#+id/buttonRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<ImageButton
android:id="#+id/buttonBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<?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:background="#mipmap/background"
android:orientation="vertical"
android:id="#+id/homemain124"
android:weightSum="3">
<RelativeLayout
android:id="#+id/paneltamrin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="something"
android:textColor="#fff"
android:id="#+id/top1"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:padding="8dp"
android:background="#drawable/textcorner"
android:layout_below="#+id/top1"
android:text="something"
android:textSize="20sp"
android:textColor="#fff"
android:id="#+id/top2"
android:fontFamily="monospace"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_marginTop="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top2"
android:text="APPLIED BY"
android:textSize="15sp"
android:id="#+id/top3"
android:textColor="#fff"
android:gravity="center_horizontal"
android:layout_marginTop="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top3"
android:text="COURT OF JUSTICE IN INDIA"
android:id="#+id/top4"
android:textSize="15sp"
android:textColor="#fff"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/paneltamrin2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="220dp"
android:layout_height="160dp"
android:src="#mipmap/book1"
android:id="#+id/image1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/paneltamrin3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="READ NOW"
android:textColor="#fff"
android:lineSpacingExtra="10dp"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"
android:id="#+id/buttonorder"
android:padding="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/orderbutton"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="13sp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:layout_below="#+id/buttonorder"
android:text="something"/>
</RelativeLayout>
</LinearLayout>
Linear layout added for 3 relative layouts
How can I put the image view below two of the text views, tv_pw and tv_un. So that in the layout the two text views are on top of the image, while the image serves as a background for that two text views. How could I do that?
Here is my xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="510dip"
android:layout_marginTop="10dip"
android:background="#DDDDDD">"
<EditText
android:id="#+id/et_pw"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_un"
android:layout_below="#+id/et_un"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="#+id/tv_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_pw"
android:layout_alignBottom="#+id/et_pw"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/et_pw"
android:text="Password:"
android:textColor="#444444"
android:textSize="10pt" />
<Button
android:id="#+id/btn_login"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="#+id/et_pw"
android:layout_centerHorizontal="true"
android:text="Login" />
<TextView
android:id="#+id/tv_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/tv_pw"
android:layout_marginTop="98dp"
android:text="User Name:"
android:textColor="#444444"
android:textSize="10pt" />
<EditText
android:id="#+id/et_un"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv_un"
android:layout_centerHorizontal="true"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_login"
android:layout_centerHorizontal="true"
android:text="" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:src="#drawable/bkground" />
There's a lot more in your XML but, focusing on what you are asking, you can use the margin attribute to overlap the textviews.
Try something like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImage">
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_marginTop="-50dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world2" />
</LinearLayout>
</RelativeLayout>
In this example I wrapped the two textviews inside a linear-layout (vertical) and set the linear-layout below the imageview and a margin of -50dp so it goes up and overlap.
HIH
Another way would be to use drawableBottom="#drawable/ic_launcher" inside your textview
If you don't care about having control on how the image scales, you can set the background of a LinearLayout that's wrapped around the TextViews.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/your_background_image_here"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_2" />
</LinearLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="510dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:gravity="center"
android:background="#DDDDDD">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="98dp">
<LinearLayout
android:layout_width="110dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bkground">
<TextView
android:id="#+id/tv_un"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User Name:"
android:textColor="#444444"
android:textSize="10pt" />
<TextView
android:id="#+id/tv_pw"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="Password:"
android:textColor="#444444"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp">
<EditText
android:id="#+id/et_un"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="text" />
<EditText
android:id="#+id/et_pw"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btn_login"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Login" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Wrap the two TextViews in linear layout with vertical orientation and assign background for linear layout.
use android:weight on the the two text views and boom
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />