How to put a textview behind a button? - android

I have this problem, that I want to elevate my "Menu" buttons but the elevation bugs and it looks like this. I figured butting an empty TextView behind them and elevating it. Yet when I do this it gets in front of the buttons and visually covers them, yet the buttons are still functioning (it looks like this). I made it to be created before the buttons, yet it still doesn't work. How to fix it?
Edit: activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PortfolioActivity">
<TextView
android:id="#+id/Background_for_buttons"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#android:color/white"
android:elevation="10dp"
android:gravity="center"
android:textColor="#FF000000" />
<Button
android:id="#+id/portfolio_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#android:color/white"
android:text="Portfolio" />
<Button
android:id="#+id/settings_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="#android:color/white"
android:text="Settings" />
<Button
android:id="#+id/home_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#android:color/white"
android:text="Overview" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="226dp"
android:padding="20dp"
android:background="#android:color/white"
android:elevation="20dp"
android:text="ASDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" />
<Button
android:id="#+id/add_coin_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:text="ADD" />
</RelativeLayout>

Your approach is wrong. Use the code below, I just used a horizontal LinearLayout inside a vertical LinearLayout for your menu, and removed your textView. WeightSum is used so that all your 3 buttons will have the same width and fill the screen width.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PortfolioActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/home_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:background="#android:color/white"
android:text="Overview" />
<Button
android:id="#+id/portfolio_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:background="#android:color/white"
android:text="Portfolio" />
<Button
android:id="#+id/settings_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:background="#android:color/white"
android:text="Settings" />
</LinearLayout>
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="226dp"
android:background="#android:color/white"
android:elevation="20dp"
android:padding="20dp"
android:text="ASDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" />
<Button
android:id="#+id/add_coin_button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:text="ADD" />
</LinearLayout>
</RelativeLayout>

Related

How to add a textview towards left and edittext towards right inside a background with delete button near to the background android

Below is the image what I required.
You can see there is blue background and inside that, it has
Trailer Number 1 which is textview and 01010 is editext (input field)
Also outside the background, there is delete button near to the blu background.
What I tried is,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/app_white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blue_light"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp">
<TextViewÃ’
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trailer number"
android:padding="#dimen/margin_5"
android:layout_margin="5dp"
android:layout_alignParentLeft="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="01010"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:layout_toRightOf="#+id/relative_1"
android:background="#drawable/ic_delete_cion" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
But delete icon is not at all displaying and also line is displaying in 01010 eddittext.
This is my screenshot.
I made some changes in ur layout and it is fit in ur requirement and fit for every device.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/relative_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/default_blue_light">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
android:padding="10dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:background="#null"
android:inputType="number"
android:padding="5dp"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_delete_icon" />
</LinearLayout>
you can achive this by only putting android:weightSum into linear layout.
try below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight=".9"
android:background="#color/blue_light"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:text="Trailer number" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#null"
android:inputType="number"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_weight=".1"
android:layout_gravity="center"
android:background="#drawable/ic_delete_cion" />
</LinearLayout>
Try this xml code : (Please replace dimensions, padding, styles with your own)
Code:
<?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="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#FFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_weight="6"
android:background="#f5f5f5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:padding="5dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:inputType="number"
android:text="01010" />
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:src="#drawable/ic_delete_black_24dp" />
</LinearLayout>
</LinearLayout>

Android studio horizontal layout troubles

So, I'm trying to get something like this.
And I am having a problem lining up the + and - buttons in the same line.
Once I have the horizontal layout, and I drag the buttons. I end up with this. I don't know how to make it work, from code or design window. Please help.
Any solution?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:orientation="horizontal">
<Button
android:id="#+id/suma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="171dp"
android:layout_weight="1"
android:onClick="incrementaContador"
android:text="+" />
<Button
android:id="#+id/resta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="169dp"
android:layout_weight="1"
android:onClick="restaContador"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<TextView
android:id="#+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Cafe del dia "
android:textAlignment="center" />
<TextView
android:id="#+id/contadorA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="64dp"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/reinicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Reinicio"
android:onClick="reseteaContador" />
</RelativeLayout>
I think you need something like this. Paste this code in your code window.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:id="#+id/titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Cafe del dia " />
<TextView
android:id="#+id/contadorA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titulo"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="4"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/contadorA"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:orientation="horizontal">
<Button
android:id="#+id/suma"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="16dp"
android:onClick="incrementaContador"
android:text="+"
android:textSize="30sp" />
<Button
android:id="#+id/resta"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="16dp"
android:onClick="restaContador"
android:text="-"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/reinicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:onClick="reseteaContador"
android:text="Reinicio" />
</RelativeLayout>
From my point of view, it is easier to get appropriate design by coding it. I am having something like this.
You've got
android:layout_alignParentTop="true"
android:layout_marginTop="171dp"
on one button and
android:layout_alignParentTop="true"
android:layout_marginBottom="169dp"
on the other.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<Button
android:id="#+id/suma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:onClick="incrementaContador"
android:text="+" />
<Button
android:id="#+id/resta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:onClick="restaContador"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<TextView
android:id="#+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Cafe del dia "
android:textAlignment="center" />
<TextView
android:id="#+id/contadorA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/reinicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Reinicio"
android:onClick="reseteaContador"
/>
</RelativeLayout>
You have too many nested views. You could just use a vertical Linear Layout as parent viewgroup and a horizontal linear layout with layout weight 1 for the middle two buttons.
For example:
<?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">
<TextView
android:id="#+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Cafe del dia "
android:textAlignment="center" />
<TextView
android:id="#+id/contadorA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:textSize="24sp"
android:text="24"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_weight="1">
<Button
android:id="#+id/suma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:onClick="incrementaContador"
android:text="+" />
<Button
android:id="#+id/resta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="restaContador"
android:text="-" />
</LinearLayout>
<Button
android:id="#+id/reinicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Reinicio"
android:onClick="reseteaContador" />
</LinearLayout>
Best if you use constraintLayout once you learn to use it.
You should instead use a ConstraintLayout to achieve what you want. It will be more efficient than using a RelativeLayout, especially nesting sub-layouts inside it. With the ConstraintLayout, you can use the GUI builder to drag the elements around the screen and get them pixel-perfect. The ConstraintLayout may require a bit of work but it is really powerful and you can get major performance gains when you have complex Viewgroup hierarchies consisting of many nested ViewGroups.
But as a solution to your problem here is the updated code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal">
<Button
android:id="#+id/suma"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginRight="15dp"
android:onClick="incrementaContador"
android:textSize="35sp"
android:text="+" />
<Button
android:id="#+id/resta"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="15dp"
android:onClick="restaContador"
android:textSize="35sp"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<TextView
android:id="#+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="Contender"
android:textAlignment="center" />
<TextView
android:id="#+id/contadorA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="35sp"
android:text="4"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/reinicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
android:onClick="reseteaContador"
android:text="Reinicio"
/>
</RelativeLayout>
See on the picture the property that will put text box below the button.
Then you get the squigly line in red circle indicating the relation.
How to space it even further down the page, I'm still working on. (you could use padding, but I'm sure there is better solution)
click

Add RelativeLayout with buttons below RecyclerView

I need to add a RelativeLayout below my RecyclerView and was able to do so, except that the button under TOTAL(R.id.total_amount_tv) does not show:
I can easily scroll through the items and it doesn't affect my RelativeLayout. I just need the button to be visible.
<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="wrap_content"
android:background="#android:color/white"
android:weightSum="1">
<android.support.v7.widget.RecyclerView
android:id="#+id/order_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/total_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/total_amount_tv"
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/total_tv"
android:textSize="20sp"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/total_amount_tv"
android:layout_marginTop="51dp"
android:background="#color/accent"
android:onClick="onClickSendOrder"
android:text="#string/order_btn"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
You need to divide the screen in to two Parts one for showing the Recyclerview and other for RelativeLayout
<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="#android:color/white"
android:orientation="vertical"
android:weightSum="10">
<android.support.v7.widget.RecyclerView
android:id="#+id/order_recycler"
android:layout_weight = "8.5"
android:layout_width="match_parent"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:layout_weight = "1.5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/total_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/total_amount_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/total_tv"
android:textSize="20sp"
android:text="Total Right"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/total_amount_tv"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
This will produce the following results
android:layout_alignParentBottom="true"
This is the likely culprit. Both TextViews are aligned at the bottom of their parent RelativeLayout. This doesn't leave room for the Button.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/downline_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/lin_result"
android:layout_marginTop="5dp" />
<LinearLayout
android:id="#+id/lin_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f8ffffff"
android:orientation="vertical"
android:paddingBottom="10dp">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginBottom="5dp"
android:background="#999898" />
<TextView
android:id="#+id/text_total_rupees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="100"
android:textAppearance="#style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
</RelativeLayout>

How can I align views justify in LinearLayout?

I want to align two buttons left and right and I'm using layout_weight property width .25 for both of buttons. But when I did it, buttons width are became %50.
This is what I want:
This is what I have:
And this is my XML layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/like"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:textColor="#212121"
android:background="#drawable/button_default"
android:layout_margin="5dp"
android:src="#drawable/like" />
<Button
android:text="NEXT"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:textColor="#FFFFFF"
android:background="#drawable/button_primary"
android:layout_margin="5dp"/>
</LinearLayout>
How can I do this?
Try this code.
<?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="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:weightSum="2">
<ImageButton
android:id="#+id/like"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#mipmap/ic_launcher"
android:src="#mipmap/ic_launcher"
android:textColor="#212121" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#mipmap/ic_launcher"
android:text="NEXT"
android:textColor="#FFFFFF" />
</LinearLayout>
</RelativeLayout>
Do it like 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="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="#+id/like"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#drawable/button_default"
android:src="#drawable/like"
android:textColor="#212121" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/button_primary"
android:text="NEXT"
android:textColor="#FFFFFF" />
</LinearLayout>
or like this:
<?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">
<ImageButton
android:id="#+id/like"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="5dp"
android:background="#drawable/button_default"
android:src="#drawable/like"
android:textColor="#212121" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:background="#drawable/button_primary"
android:text="NEXT"
android:textColor="#FFFFFF" />
</RelativeLayout>

Center Vertically not working in Android below 20

I created in my application list element with actions to swiping. The problem is that when one view is showing after swiping, the delete icon is not showing in vertical center. The interesting thing is that the problem is only in Android below 20 SDK.
ListElement.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listObjectRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/divider"
android:layout_alignParentTop="true"
android:background="#color/swipeBackground"
android:tag="reveal-left">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="#drawable/ic_delete_white_24dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/divider"
android:layout_alignParentTop="true"
android:background="#color/swipeBackground"
android:tag="reveal-right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_delete_white_24dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/contextRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:tag="front">
<Button
android:id="#+id/roundButton"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#drawable/round_0"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif-medium"
android:text="Hello"
android:textColor="#color/primaryDark" />
</RelativeLayout>
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_below="#id/contextRelativeLayout"
android:background="#color/background" />
</RelativeLayout>

Categories

Resources