Scroll up Relative Layout when scrolling up listview - java

I'm creating an application. and the user information is shown in a relative layout. Under the relative layout is a listview with items the user created. I want if you scroll down in the List View that the Relative Layout scroll up and eventually disappeared, and the list view is stretched over the whole screen.
Like you have in de facebook app.
Facebook Scrolling image
How do I do this, this is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6">
<ImageView
android:id="#+id/BackgroundPictureOther"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#eeeeee" />
<ImageView
android:id="#+id/profileOther"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#444444"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"/>
<TextView
android:id="#+id/profileName"
android:layout_width="wrap_content"
android:minWidth="150dp"
android:layout_centerHorizontal="true"
android:textColor="#aaa"
android:textAlignment="center"
android:textSize="30sp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"></ListView>
</LinearLayout>
</merge>
Thanks in advance!

You have 2 options here:
1) You should put your entire layout inside NestedScrollView and change ListView into RecyclerView.
2) Or you can set your layout with profile picture as header view for listview.
For this you need to put your layout with profile in other xml layout file, then inflate it in code and use listview.addHeaderView(view v)

Related

Resizing of Layout with Recycler View when the soft keyboard appears

I have a layout which contains Recycler View,toolbar and an EditText at the bottom of the Layout.I want to resize the recycler view when the soft keyboard appears.The toolbar should remain on the top and the edittext should move up with the keyboard.Only the recycler view should be resized.
The layout code is as follows
<LinearLayout 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"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:background="#ffffff">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#fff"
android:elevation="4dp"
app:title="Toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center"
android:orientation="horizontal"
android:padding="8dp">
<EditText
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:backgroundTint="#757575"
android:textCursorDrawable="#drawable/cursor_color"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
I am using the window in full screen mode.The Current situation is that the entire layout is pushed upwards when the soft keyboard appears,toolbar is invisible and only a part of the recycler view is visible.
Thank you!
add android:windowSoftInputMode="adjustResize" to the activity tag on the manifest.xml

CardView doesn't display correctly in different screen densities?

I have a ViewPager with Cardviews, cardviews are displays correctly on certaing devices but in most are displays slimly.
The ViewPager is in a Fragment.
I'm using LinearLayout to CardView definition, I tried Relative but I have same problem.
https://ibb.co/kyNF5Yz "Example from differents devices"
Item.xml
https://gist.github.com/Bryan9797/1eda5e7d02d1a12140115a539f164e3e
Fragment_bateria.xml
https://gist.github.com/Bryan9797/b5d7b16a6d0599b7fd7f593226a4523d
activity_main.xml
https://gist.github.com/Bryan9797/632461d73286afa5493167048b8e19c0
I expect display Cardview correctly on different devices.
you can use sdp library for responsive XML for all devices.
https://github.com/intuit/sdp
you can install this dependency in gradle and us this sdp instead of dp.
you can set this sdp and set height to wrap_content in your xml layout as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_20sdp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="#dimen/_350sdp"
android:scaleType="centerCrop"
android:src="#color/colorAccent" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_marginLeft="#dimen/_15sdp"
android:layout_marginTop="10dp"
android:text="Escritorio ejecutivo"
android:textColor="#262626"
android:textSize="#dimen/_20ssp" />
<TextView
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_marginLeft="#dimen/_15sdp"
android:layout_marginTop="#dimen/_3sdp"
android:layout_marginRight="#dimen/_15sdp"
android:drawablePadding="#dimen/_10sdp"
android:ellipsize="end"
android:maxLines="4"
android:text="Escritorio ejecutivo"
android:textSize="#dimen/_15ssp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>

How to Control Visibility of items in a Linear Layout in my App?

I have a Vertical linear layout with 2 item. One is a is a customview which is extended from a framelayout and the 2nd one is a textview with a drawable as background. The visibility have to be controlled dynamically from gone to visible.
The issue is that when i change the visibility of the item from gone to visible the order is not coming as i intended. The the second item is below the customview. I want it to come as the 2nd item, below the customview
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:textureview="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="#+id/comment_holder"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.custom_views.CircularFrameLayout
android:id="#+id/comment_holder_circular_layout"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/user_avatar"
android:visibility="gone"
android:layout_gravity="center_horizontal"
android:layout_width="#dimen/comment_avatar_width"
android:layout_height="#dimen/comment_avatar_width" />
<com.custom_views.PlaybackTextureView
android:visibility="gone"
android:id="#+id/playback_texture_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
textureview:isAuthorMode="true"/>
</com.custom_views.CircularFrameLayout>
<LinearLayout
android:visibility="gone"
android:id="#+id/c_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="16dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:background="#drawable/chat_bubble_top_arrow_orange"
android:orientation="vertical">
<TextView
android:id="#+id/video_comment_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#color/black_50"
android:fontFamily="sans-serif" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
NOTE: I tried adding weight to the custom layout as 1. But it still didnt help.

Android: Swipe to refresh gets stuck on a recycler view with view pager

Here is my XML code
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/flipper">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/headerLayout"
android:background="#color/background_color"
android:visibility="visible">
<android.support.v7.widget.RecyclerView
android:id="#+id/list_appointment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="#+id/emptyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone">
<ImageView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_event_note"
android:textAppearance="?android:textAppearanceMedium" />
</RelativeLayout>
</FrameLayout>
The RecyclerViews adapter supports two types of views one is CardView and another is ViewPager.
When I swipe to refresh, the circular refresh icon freezes on top of the ViewPager.onrefresh method is called after I tap the refresh icon again.Is there any fix to this issue?

How to add view below listview

I found few topics here on SO, but they are not what i'm searching. One of them is this one Android ListActivity - how to add a view below the ListView?
I know i can position a View (like button) at the footer of listview. That means desired View will position itself AFTER last view.
I want to know how to position a View at the end of the screen (Just below).
Please check two pictures below:
I want to do this in java code. Any ideas?
try the following code
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
>
</ListView>
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
Use a Relative Layout. Set the Height of Listview to the required height. Place the button relative to the listview at the button.
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
tools:context=".MainActivity" >
<ListView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="122dp"
android:text="Button" />
</RelativeLayout>

Categories

Resources