Android RelativeLayout zIndex not working (anymore) - android

I don't understand this issue. I'm pretty sure I used to do this, yet in this case, the zindex ordering is not followed, and the TextView below is hidden behind the button:
<?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">
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="50dp" />
<TextView
android:textColor="#color/black"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
I have restarted Android Studio, but even worse, this is the same on my device too, so its not an Android Studio bug. What is the issue here exactly?

Please use the elevation
android:elevation="10dp"
here is you can see your solution

If you add any views to Relative Layout, It places your view above another view if you don't use layout alignment like layout_above/layout_below/layout_leftof or rightof etc

Related

Relative Layout didn't Work in Android Studio Always Shows Constraint Layout in Design View

After the android studio update, The relative layout didn't work android studio always shows constraint layout in design view.
Even I selected the relative layout but it always asked for constraining the widgets.
I already tried to search online on different forums but no solution I found.
In this, I used 2 edit texts as shown in the image I want relative layout because it's more convenient but now it's not working.
Can someone please help to find where I am doing mistake?
Here is the design view
design view
Here is the XML of the 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">
<EditText
android:id="#+id/txt_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="enter email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/txt_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_email"
android:hint="enter password"
android:inputType="textPassword" />
<Button
android:id="#+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_password"
android:text="Submit" />
</RelativeLayout>
[1]: https://i.stack.imgur.com/zlpik.png
The constraints has the same functionality as the below or start_of that the relative_layout had... but
i suggest that you replace your
android:layout_below
to this or or if you don't needed also can be constrained into the parent like:
app:layout_constraintTop_toBottomOf="parent" or "#id/your_component_id
but remember that this can work only if all the childrens are wrapped inside a constraint_layout. and wrap your relative layout inside of a constraint_layout.

Android Imagebutton is clipped

I'm having issues with my Activity and an ImageButton inside it. It looks like it is clipping:
This is the XML of the corresponding activity:
<?xml version="1.0" encoding="utf-8"?>
<!-- A RecyclerView with some commonly used attributes -->
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="#+id/todo_linear_layout"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:adjustViewBounds="true"
app:srcCompat="#android:drawable/ic_input_add" />
<EditText
android:id="#+id/edittodo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20px"
android:layout_weight="5"
android:textColor="#android:color/black" />
</LinearLayout>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/todo_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Additionally the Layout Designer in Android Studio shows the Layout correctly:
Where is the problem here? I already tried to change margin or padding values but the Button is still clipping in the running app on my android device.
I believe that what's happening is that the device you're running your app on doesn't have the #android:drawable/ic_input_add drawable.
I tried running the code you posted, and everything worked for me. However, if I delete the app:srcCompat attribute from the <ImageButton> tag, then I get the same behavior you posted in your first screenshot.
In general, you can't rely on 100% of devices having #android: resources. Some manufacturers remove resources, and others replace the values with nonsense (I've seen #android:color/white come through as gray, for example).
I recommend creating your own drawable (maybe even just manually copying the one from Android and adding it to your project), and referencing that instead.
app:srcCompat="#drawable/your_own_add"
Changing the app:srcCompat to:
android:src="#android:drawable/ic_input_add" did it! So the issue was, that the device didn't find that icon and displayed just something gray.

Android Layout xml "buttons stacking" (newbie )

I just started with android development. I just need a screen with some buttons on it that can contact a webserver, to trigger an action there, but i have not even gotten that far.
When i add buttons to the layout, even if they are nicely sided by side, they end up ontop of each other, with the button created last ontop.
And furtermore i have changed the color, but it does not seem to be moved end up in the simulator.
This is a fresh design (2nd try) and i dont understand what is going on. I dont really know what files to include :)
I realize this is something simple, but im just overwhelmed
thank you
Lasse
Phone and design view
You're probably using a FrameLayout, which just stacks things on top of each other and only supports gravity.
For your use case, you can use a LinearLayout, a RelativeLayout or a ConstraintLayout. Here's an example using 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:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Select releases since last candy fix" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:text="Button 1" />
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:text="Button 2" />
</LinearLayout>
</LinearLayout>
Have a look at the different layouts to see which one better fits your needs, ConstraintLayout would allow you to flatten your layout, which is good for performance.

How to make a WhatsApp like `RecyclerView`?

This may be possible of duplicate question i have tried all things none of it works i need to make whatsapp like chat model using RecyclerView and at the bottom EditText and a Button bottom my problem is i can have EditText and bottom at the bottom but i need scroll to view that EditText and Button, what i should have when user enter that page EditText and Buttonb should appear without scrolling and one more problem there is lots of space between two items in thatRecyclerView` how to reduce that space let me post what i did so far:
My Recyclerview ChatLayout:
<?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"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/constraint_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="4">
<EditText
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Message"
android:lines="1" />
<Button
android:id="#+id/btn_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Send" />
</LinearLayout>
</RelativeLayout>
How to do this as am new for android development someone please help me!
You should change the android:height in layout that u use in your RecyclerViewAdapter to wrap_content
And also in your manifest
<activity
...
android:windowSoftInputMode="adjustPan"
...
></activity>
Their are many libraries out there.This library is a sample Android App which can be used as a starter application for a chat application.You can take reference or implemented this library in your project
check your row item(layout xml file) which is used in your viewholder. I think you have used match_parent in your parent view. Make it as wrap_content.
For that scrolling issue, check your code for smoothScrollToPosition(int). may be you have used this method in your code.

Adding padding on android AutoCompleteTextView popup

For the last two hour and a half i had been trying to do something really simple: change the padding in the Android's AutoCompleteTextView's popup (the one that shows the auto complete options).
i'm trying to do this because the item in my app has the height of the text (i'm not sure why), so i want to make it easier to click on. But every think i could find didn't work at all.
So i really would be glad if anyone could spot a light in this problem or give an alternative solution.
And just for the record, i'm using android studio, and i had removed the support API (since my min API is 16), so my app is using 100% native resorts only.
I just found a way to make it, i had to make a custom view layout with an textview already including the item's padding. Than i created a custom adapter with uses this layout.
The layout goes like this
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_margin="0dp"
android:paddingLeft="#dimen/thin_margin"
android:paddingRight="#dimen/thin_margin"
android:paddingTop="#dimen/list_1line_item_padding"
android:paddingBottom="#dimen/list_1line_item_padding"/>
And in the custom adapter just used it in the getView method
itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_15"
android:paddingBottom="#dimen/dp_15"
android:id="#+id/parentid">
<AutoCompleteTextView
android:id="#+id/address_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_gray_bg"
android:drawableRight="#drawable/icon_search_smaller"
android:gravity="center_vertical"
android:hint="Start typing location"
android:inputType="textCapWords"
android:popupBackground="#drawable/auto_location_popup_bg"
android:textColor="#color/black"
android:textColorHint="#color/dark_grey"
android:textSize="16sp"
android:visibility="visible"
android:dropDownWidth="wrap_content"
android:dropDownAnchor="#+id/parentid">/>
<requestFocus />
</RelativeLayout>
</RelativeLayout>
define another relative layout wrapping only the autocomplete textview and the button. look at this link
Android layout padding is ignored by dropdown

Categories

Resources