I can't find this component in the material design documentation and I'd like to know how to do it.
I've never seen it as a pre-built component, maybe someone can correct me if I'm wrong.
But replicating it would be fairly simple.
2 Buttons and a ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content">
<Button
app:layout_constraintHorizontal_weight="6"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="#+id/sign_in_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:text="Sign In" />
<Button
app:layout_constraintHorizontal_weight="4"
app:layout_constraintLeft_toLeftOf="#+id/sign_in_button"
app:layout_constraintTop_toTopOf="#+id/sign_in_button"
app:layout_constraintBottom_toBottomOf="#+id/sign_in_button"
android:id="#+id/register_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Register" />
</androidx.constraintlayout.widget.ConstraintLayout >
You will have to tweak it for your use case but this should be like 90% of what you need. You may also have to create a custom button to get that more rounded shape. This is an older tutorial on how to customize buttons it should still be relevant. https://www.codebrainer.com/blog/13-designs-for-buttons-every-android-beginner-should-know
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
So I have a ListView in which I have filled random values. I also have a SearchView above the ListView. Whenever I click the SearchView, the Listview goes up. I do not want the Listview to be moved from its place. I am attaching two images for reference.
This is when the searchview is not active
This is when the searchview is active
Edit:: On emulator it works fine
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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/NavigationBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="17dp"
android:adjustViewBounds="true"
android:padding="7dp"
android:src="#drawable/navigation_bar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="65dp"
android:layout_marginLeft="65dp"
android:layout_marginTop="17dp"
android:fontFamily="#font/product_sans_bold"
android:text="Library"
android:textColor="#color/green"
android:textSize="39sp" />
<ListView
android:id="#+id/ListView"
android:layout_width="match_parent"
android:layout_height="649dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginStart="0dp"
android:layout_marginBottom="0dp"
android:divider="#null" />
<androidx.appcompat.widget.SearchView
android:layout_width="362dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:background="#drawable/search_background"
app:iconifiedByDefault="false"
app:queryBackground="#android:color/transparent"
app:queryHint="Search music"
app:searchHintIcon="#null"
app:searchIcon="#drawable/search" />
</RelativeLayout>
`
NOTE: I HAVE A CUSTOM LISTVIEW IN WHICH I AM FILLING VALUES. I HAVE NOT IMPLEMENTED SEARCHVIEW CODE TILL NOW.
Adding these lines of code solved the problem.
Hope this may help some coder.
android:focusableInTouchMode="false" android:isScrollContainer="false"
I need to use a ValueAnimator to make a custom "drop field" appear when the user drags a certain view. (I want to change the field from gone, height = 0 to visible, height = wrap_content).
I've tried the solution of this question: How to animate to wrap_content?
The answer there worked when I used it on a single TextView, but when I tried to apply it to a LinearLayout with multiple text views it animated to a too large height value, then, when the animation finished, snapped back to the correct one. The layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="match_parent"
android:paddingVertical="8dp"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
android:paddingVertical="8dp"
android:gravity="center"
android:textSize="18sp"/>
</LinearLayout>
Using animateLayoutChanges didn't work for me either, and I want to use a custom animator anyway.
I'm using C# in Xamarin, but answering with Android Studio Java code is acceptable too, I'll translate it to C#.
This should be caused by measuring the children views during Measure, so you can change your xaml like this ,change your children views's width to wrap_content:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_weight="5"
android:layout_height="match_parent"
android:paddingVertical="8dp"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_weight="2"
android:layout_height="match_parent"
android:paddingVertical="8dp"
android:gravity="center"
android:textSize="18sp"/>
</LinearLayout>
ok so i'm currently learning android and i am trying to make a memory app where you have to find 2 matching pictures.
I have almost finished it but there is one problem that is bugging me, i looked it up and someone else had the same problem but the only answer he got was to make the image button a fixed dp size, but i don't think that's a solution if you are making an app for a variety of different android devices.
I made the images image views and they are all the same image but every time someone presses one of the image views it changes to a certain image that is fixed for that spot for that round.
The problem is every time an image is pressed the whole layout moves slightly but enough to be noticed and get annoyed by it, how can i fix this without giving them a fixed dp size.
Thanks :).
i made it with table layout inside a linear layout, this is one of the rows.
<TableLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/ImageView1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp" />
<ImageView
android:id="#+id/ImageView2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp" />
<ImageView
android:id="#+id/ImageView3"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp" />
<ImageView
android:id="#+id/ImageView4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp" />
</TableRow>
I'm really pulling my hair out over this one. Some background. I have a list of items that all have checkboxes next to them. When you deselect a checkbox, a button appears that allows you to delete the item from the list. This seems backwards at first but we only want "selected" items to be eligible for further processing, etc. This is my layout:
<RelativeLayout android:id="#+id/rlBlahBlah"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBox android:text=""
android:id="#+id/cbDeleteItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
/>
<TextView android:text=""
android:id="#+id/tvItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:paddingLeft="3dip"
android:paddingRight="3dip"
android:paddingTop="13dip"
android:gravity="fill_vertical"
android:layout_toRightOf="#id/cbDeleteItem"
/>
<Button android:layout_height="wrap_content"
android:id="#+id/btnDelete"
android:text="Delete"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:focusable="false"
/>
</RelativeLayout>
I cannot get the 3 items to center vertically in my row to save my life. layout_gravity, gravity, layout_centerVertical, none of it works. I'm sure my issue is some tiny setting to flip somewhere, but I'm really at wits end on this.
edit: I know the textview is "fill_vertical", that's some random stuff I was trying.
This attribute worked for me centering a Button using RelativeLayout:
android:layout_centerInParent="true"
See this posting:
Can you center a Button in RelativeLayout?
Your problem is probably not due to the layout, but how you are inflating the layout. In fact, it might even be my fault, depending on where you learned your technique...
To quote the omnipresent Romain Guy:
the correct usage of inflate() in
adapters is:
inflate(layoutId, parent, false);
Passing the parent (given to you as a
parameter in getView()) allows the UI
toolkit to create the appropriate
LayoutParams object. Passing false
tells the toolkit to NOT call
parent.addView(theInflateChild), since
ListView will do its own magic later
on.
If you use inflate(layoutId, null), as I have traditionally advised, life is OK unless you try using RelativeLayout as the base layout of the rows and try to use vertical centering.
I will be updating my books and such to reflect the new advice in the coming weeks.
Using RelativeLayout, I had no luck with gravity nor layout_gravity.
But android:layout_centerVertical="true" worked for me positioned in the child of my RelativeLayout, so you can keep it if you need.
Here is a layout that ended up doing exactly what I wanted. I ditched RelativeLayout once I learned that it ignores layout_gravity attributes (of course now I can't find the post). Either way, nested LinearLayouts did the trick for me:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:id="#+id/llBlahBlahRowMain"
android:padding="6dip">
<CheckBox android:text=""
android:id="#+id/cbDeleteItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content">
<TextView
android:text="blah blah dynamically replaced text"
android:id="#+id/tvItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="14dip"
android:paddingLeft="3dip"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnDelete"
android:text="Delete"
android:layout_gravity="center_vertical"
android:focusable="false"
/>
</LinearLayout>
Have you tried android:gravity="center_horizontal" as referenced here
I did an alternative solution, that worked for me. I put, on my textbox element, the property android:layout_height="fill_parent". This way, the text element filled all hieght of parent, so the contents were aligned correctly :)
<TextView android:id="#+id/principal_li_descricao"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_marginLeft="10dip"
android:textColor="#ff000000"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_alignBottom="#+id/principal_li_icone"
android:layout_toRightOf="#+id/principal_li_icone"/>
Thanks