SwipeRefreshLayout hiding part of last ListView item - android

<android.support.constraint.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"
tools:context="com.partyspottr.appdir.ui.mainfragments.eventchildfragments.alle_eventer_fragment">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_layout_events"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginStart="#dimen/_8sdp"
android:layout_marginTop="#dimen/_5sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/search_alle_eventer"
app:layout_constraintVertical_bias="0.0">
<ListView
android:id="#+id/lvalle_eventer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/transparent"
android:dividerHeight="#dimen/_20sdp"
android:scrollbarSize="#dimen/_3sdp"
android:scrollbarThumbVertical="#color/lightred"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<EditText
android:id="#+id/search_alle_eventer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginStart="#dimen/_8sdp"
android:layout_marginTop="#dimen/_90sdp"
android:background="#drawable/border_rounded"
android:hint="Search.."
android:inputType="text"
android:paddingEnd="#dimen/_10sdp"
android:paddingStart="#dimen/_10sdp"
android:textColor="#android:color/black"
android:textSize="#dimen/_15ssp"
app:layout_constraintEnd_toEndOf="#+id/swipe_layout_events"
app:layout_constraintStart_toStartOf="#+id/swipe_layout_events"
app:layout_constraintTop_toTopOf="parent" />
This is my layout XML, containing a parent (ConstraintLayout), a SwipeRefreshLayout with a ListView as child, and an EditText which i use to search items inside the ListView.
This layout is used as a fragment, so i have a button outside of this layout, when i press this button, the EditText either shows or doesn't, i do this with this code:
search_alle_eventer.setVisibility(search_alle_eventer.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
ViewGroup.LayoutParams params = search_alle_eventer.getLayoutParams();
if(search_alle_eventer.getVisibility() == View.INVISIBLE)
params.height = 0;
else {
params.height = WRAP_CONTENT;
search_alle_eventer.setLayoutParams(params);
Now, the problem im having is when the EditText is showing (WRAP_CONTENT), when i scroll to the bottom of the ListView, the last item is cut off. How can i fix this?

you can set margin from bottom to ListView. android:marginBottom = "50dp"
Or try with relative layout like this
< 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="com.partyspottr.appdir.ui.mainfragments.eventchildfragments.alle_eventer_fragment">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_layout_events"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginStart="#dimen/_8sdp"
android:layout_marginTop="#dimen/_5sdp"
>
<ListView
android:id="#+id/lvalle_eventer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/transparent"
android:dividerHeight="#dimen/_20sdp"
android:scrollbarSize="#dimen/_3sdp"
android:scrollbarThumbVertical="#color/lightred"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<EditText
android:id="#+id/search_alle_eventer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginStart="#dimen/_8sdp"
android:layout_marginTop="#dimen/_90sdp"
android:background="#drawable/border_rounded"
android:hint="Search.."
android:inputType="text"
android:paddingEnd="#dimen/_10sdp"
android:paddingStart="#dimen/_10sdp"
android:textColor="#android:color/black"
android:textSize="#dimen/_15ssp"
/>
</RelativeLayout>

Alright, thanks for you help, but my case is a special needs case, whatever im doing, im sure is not the correct way, but i'll let it be.
Fixed it by adding some more code inside the OnClickListener of the button i mentioned:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
if(search_alle_eventer.getVisibility() == View.INVISIBLE)
listView.setPadding(0, 0, 0, 0);
else
listView.setPadding(0, 0, 0, search_alle_eventer.getHeight());
}
}, 100);
Adding some padding on the ListView whenever the EditText is visible did the trick for me.
EDIT: Thank you Mark Keen for pointing out the container for the fragments, I was being retarded not thinking straight. I fixed it by resizing the container.
Tbh, sorry for this question.

Related

How do I programmatically distribute child views evenly in a horizontal linear layout?

I have a view like this:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/sample_icon_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:src="#drawable/active_state"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/sample_item_bar_iv"
android:layout_width="128dp"
android:layout_height="1dp"
android:background="#color/brown_grey"
app:layout_constraintBottom_toBottomOf="#id/sample_icon_iv"
app:layout_constraintStart_toEndOf="#id/sample_icon_iv"
app:layout_constraintTop_toTopOf="#id/sample_icon_iv"
/>
<TextView
android:id="#+id/leave_planner_item_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="26 March"
app:layout_constraintEnd_toStartOf="#+id/sample_item_bar_iv"
app:layout_constraintStart_toStartOf="#+id/sample_icon_iv"
app:layout_constraintTop_toBottomOf="#+id/sample_icon_iv"
tools:text="26 March" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
I need to inflate this view x times and show those evenly distributed in a horizontal scrollable fashion. I tried adding weight 1 to the inflated views before adding to the parent, but still doesn't seem to work. I also face spacing issues between the bar and the next icon. But if I remove the margin, I am not able to center the text under the icon.
This is how I would like to see the views
How do I achieve this?
Wrap your views in LinearLayout. Determine how many childs you want it to have and then set it like so:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
This example will create 3 buttons that take up the entire width of the screen, each button will get 1/3 of the screen width.
To do so programmatically:
LinearLayout layout = findViewById(R.id.yourLayoutID);
Button b = new Button(); // Or, if you want something more complicated than a simple object, you can do View v = inflater.inflate(R.layout.your_layout, null);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
p.weight = 1;
b.setLayoutParams(p);
layout.addView(b);
that's the general idea

Enable button after user scrolled to the bottom of ScrollView Android

I wanna achieve the following be behavior for one screen of my app.
I have a fragment's layout with ConstraintLayout as it's parent. Inside ConstraintLayout I have a ScrollView with nested ConstraintLayout (nested ConstraintLayout contains ImageView and TextView) and simple Button below the ScrollView.
I wanna enable button as soon as user reaches to the bottom of ScrollView and disable when user scrolls up.
Layout is below.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
>
<ScrollView
android:id="#+id/scrollableView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="#id/elevationShadow"
app:layout_constraintTop_toBottomOf="#id/appbar">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_marginStart="#dimen/spacing_large"
android:layout_marginEnd="#dimen/spacing_large"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/user_image"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_gravity="center"
android:layout_marginTop="#dimen/spacing_large"
android:src="#drawable/user_image"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="#+id/heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/text_size_xxlarge"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="#color/black_color"
android:layout_marginTop="#dimen/spacing_large"
tools:text="Tools text"
android:textAppearance="?tvptTextAppearanceBody"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_image"
/>
<TextView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_large"
android:textAlignment="center"
android:textSize="#dimen/user_info_content_text_size"
android:textAppearance="?tvptTextAppearanceBody"
android:textColor="#color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/heading"
tools:text="Tools test content"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<View
android:id="#+id/elevationShadow"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#drawable/shadow_elevation"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="#dimen/user_info_activity_confirm_button_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#id/button_confirm"/>
<com.travelportdigital.android.compasswidget.button.PercentageBasedStateButton
android:id="#+id/button_confirm"
style="#style/PrimaryButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_marginBottom="#dimen/user_info_activity_confirm_button_margin"
android:text="#string/user_info_continueButton_title"
android:textAllCaps="true"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
The problem is that content for TextView which is inside ScrollView can both long and short. That's why I had to add ScrollView if the content is long.
By the small piece of code I was able to achieve the behavior I needed with one small remark.
fun addScrollChangeListener() {
scrollView.viewTreeObserver
.addOnScrollChangedListener {
enableContinueButton(scrollView.getChildAt(0).bottom <= scrollView.height + scrollView.scrollY)
}
}
And the code above works fine for the scenario when content is long (when user arrives to this screen Continue button is disabled and when user scrolls to the bottom of the scroll view it become enabled if user scrolls up it becomes disabled again.
I wanna update this logic to enable button when user arrives to this screen and content of TextView inside ScrollView is short (no need scrolling for this scenario).
I made some researches in Google and could not find the solution which would work for me.
In onViewCreated() method I added logic to disable or enable button when user arrives to this screen.
enableContinueButton(!isScrollingRequired())
I tried this implementation
private fun isScrollingRequired(): Boolean {
val view = scrollView.getChildAt(scrollView.childCount - 1) as View
val diff = view.bottom - (scrollView.height + scrollView.scrollY)
return diff != 0
}
and this
return if (child != null) {
val childHeight = child.height
scrollView.height <= childHeight + scrollView.paddingTop + scrollView.paddingBottom;
} else {
false
}
but it did not work, because ScrollView height and it's child height is always 0
Looking forward your advices.
Regards,
Alex
I dont know is this what you want to do but it should be one of the solution.
I think you can just simply add the button in the "ScrollView" so when user scrolls at the bottom, user will see the button and when user scrolls up, user cannot press the button as well.
Below layout .XML works for me, Using ScrollView with ConstraintLayout:
(you may need extra dependencies)
<ScrollView
android:id="#+id/msg_scroll"
android:layout_width="0dp"
android:layout_height="200dp"
android:fillViewport="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/infoSumm">
<!--Display the <ScrollView> under <TextView>"#+id/infoSumm" -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inside_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/infoDetail"
android:text=""
android:layout_marginTop="12dp"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="240dp"
app:layout_constraintTop_toTopOf="#id/inside_scroll"
app:layout_constraintStart_toStartOf="parent"
tools:text="Info Detail"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_infoClose"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_field_spacing"
android:backgroundTint="#color/colorPrimary"
android:textAppearance="#style/TextAppearance.MaterialComponents.Button"
android:textAlignment="center"
android:textStyle="bold"
android:textAllCaps="false"
android:textSize="20sp"
android:textColor="#color/colorWhite"
android:text="#string/btn_Close"
android:paddingTop="10dp"
android:paddingBottom="10dp"
app:cornerRadius="25dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/infoDetail"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Add dynamic view to specific RecyclerView.Adapter

I'm currently testing my code for situations where a RecyclerView.Adapter needs additional information to be displayed in it. Using the code below which is inside onBindViewHolder, I was able to make this work.
TableRow row = new TableRow(mCtx);
row.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
row.setOrientation(LinearLayout.VERTICAL);
TextView lbl = new TextView(mCtx);
lbl.setText("Desc1");
TextView lbl2 = new TextView(mCtx);
lbl2.setText("54.77");
row.addView(lbl);
row.addView(lbl2);
holder.binding.tblTicketItemDetails.addView(row);
That code is always called inside OnBindViewHolder to simulate that each item have additional info in them. If I keep creating an item by pressing a Button, the additional info increases for each item.
How do I target the specific adapter's layout while using DataBinding?
This is the layout that I am using for RecyclerView.Adapter.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="ticket_item"
type="com.example.com.TicketItem" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:weightSum="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/lblTicketItemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:text="#{ticket_item.description}"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Test Text" />
<TextView
android:id="#+id/lblTicketItemPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:padding="8dp"
android:text="#{ticket_item.price}"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Test Text" />
</TableRow>
<TableLayout
android:id="#+id/tblTicketItemDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableRow6">
</TableLayout>
</android.support.constraint.ConstraintLayout>
</layout>
I want to add a TableRow with 2 TextViews in tblTicketItemDetails if needed. What is the best way to do this? If I can't do it while using DataBinding, then I would switch to the old way.
I usually add dynamic views like this using Databinding:
#BindingAdapter({"addDynamicView", "position"})
public static void addDynamicView(TableLayout layout, TicketItem item, int position) {
// LayoutInflater inflater = LayoutInflater.from(layout.getContext()); // if you need layout inflater
for (int i = 0; i <= position; i++) { // loop to whatever condition you have
TextView lbl = new TextView(layout.getContext());
lbl.setText("Desc1");
layout.addView(lbl);
}
}
Modify TableLayout in xml,
<TableLayout
android:id="#+id/tblTicketItemDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableRow6"
app:addDynamicView = "#{ticket_item}"
app:position = "#{position}">
Declare a new variable in xml,
<variable
name="position"
type="int" />
Send position from Java to xml
holder.binding.setVariable(BR.position, position);
or
holder.binding.setPosition(position);

Scroll firebase Recyclerview inside a scrollview to the last item inserted

I've been through several solutions over the stack overflow but could not achieve the desired result. I have a firebase recyclerview for a comment section. The firebase recyclerview exist with in the scroll view as am scroll some other part of the layout as well with the normal firebase recyclerview. I've set RecyclerView.setNestedScrollingEnabled(false), so the scrollview can scroll smoothly. right now I'm able to successfully scroll through out the layout but my problem only arises when I enter the activity the layout is shown from the top which is something, I don't want. I want the firebase recyclerview or the scroll view to be shown from the last item which is in the bottom. Also I want to the RecyclerView to automatically scroll to the last item position whenever the user enters a new comment
Any Help would be appreciated thank you
Below is my code
the code inside the oncreate for initialization
replyInDetailCommentsRecyclerView = findViewById(R.id.replyInDetailCommentsRecyclerView);
linearLayoutManager1 = new LinearLayoutManager(this);
replyInDetailCommentsRecyclerView.setLayoutManager(linearLayoutManager1);
replyInDetailCommentsRecyclerView.setNestedScrollingEnabled(false);
The code inside the firebase recyclerview, I've only added the relevant part to the problem. hope it helps
adapter1.startListening();
adapter1.notifyDataSetChanged();
adapter1.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
#Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
int friendlyMessageCount = adapter1.getItemCount();
int lastVisiblePosition =
linearLayoutManager1.findLastCompletelyVisibleItemPosition();
if (lastVisiblePosition == -1 ||
(positionStart >= (friendlyMessageCount - 1) &&
lastVisiblePosition == (positionStart - 1))) {
linearLayoutManager1.scrollToPosition(positionStart);
} else {
replyInDetailCommentsRecyclerView.scrollToPosition(adapter1.getItemCount() - 1);
}
}
});
replyInDetailCommentsRecyclerView.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
My XML Code
<ScrollView
android:layout_below="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:layout_marginBottom="50dp"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/RelativeLayout5"
android:layout_width="match_parent"
android:layout_below="#id/RelativeLayout1"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/RelativeLayout4">
<android.support.v7.widget.RecyclerView
android:id="#+id/replyInDetailCommentsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageInDetailComments"
android:layout_width="30dp"
android:src="#drawable/profile"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_height="30dp"/>
<android.support.v7.widget.AppCompatTextView
android:id="#+id/nameInDetailComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:layout_alignTop="#+id/imageInDetailComments"
tools:text="Saqib"
android:layout_toRightOf="#+id/imageInDetailComments"
android:layout_marginLeft="5dp"
android:textColor="#096697"
android:layout_toEndOf="#+id/imageInDetailComments"
android:layout_marginStart="5dp" />
<android.support.v7.widget.AppCompatRatingBar
android:id="#+id/ratingInDetailComments"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:max="5"
android:numStars="5"
android:progressBackgroundTint="#color/colorAccent"
android:progressTint="#color/colorAccent"
android:rating="0.0"
android:secondaryProgressTint="#color/colorAccent"
android:stepSize="0.0"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageInDetailComments"
android:layout_marginLeft="5dp"
android:layout_below="#+id/nameInDetailComments"
android:layout_marginStart="5dp"
android:layout_toEndOf="#+id/imageInDetailComments" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/userCommentInDetailComments"
android:layout_width="0dp"
android:layout_below="#+id/ratingInDetailComments"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/imageInDetailComments"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:background="#efeeee"
android:padding="5dp"
android:text="i can do it mate, my bidding price includes gotaskie fee"
/>
<View
android:layout_below="#+id/userCommentInDetailComments"
android:layout_marginTop="8dp"
android:id="#+id/lineAboveCommentsRecyclerView"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#dad8d8"
/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
You can use NestedScrollView instead of ScrollView

Change RelativeLayout height as user scrolls in scrollview

I'm trying to change the height of RelativeLayout as user scrolls, so it smoothly moves up. It's kinda working but its all flickering and glitching.
I tried to use setTranslationY, but that doesn't move the scrollview with the RelativeLayout.
int top = mScrollView.getScrollY();
int maxRelative = formulas.dpToPx(250);
int actualRelative = (int)((1.0-((float)top)/300.0)*((float)maxRelative));
RelativeLayout.LayoutParams layout_description = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
actualRelative);
mCollapsingLayout.setLayoutParams(layout_description);
mCollapsingLayout.requestLayout();
This is how it looks
http://imgur.com/7PL6Yt5
If you have any better idea how to shrink the RelativeLayout as you scroll, its appreciated.
Edit: here's my xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:id="#+id/collapsing.view">
<ImageView
android:id="#+id/collapsing.view.image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/theflash"
android:tint="#7F000000"
android:scaleType="centerCrop"/>
<ImageButton
android:id="#+id/favorite.button"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:src="#drawable/favorite_button"
/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingBottom="30px">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The Flash"
android:textColor="#fff"
android:textSize="25sp"
android:layout_centerInParent="true"
/>
</FrameLayout>
</RelativeLayout>
<ScrollView
android:id="#+id/detail.scrollview"
android:layout_below="#+id/collapsing.view"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
There are several approaches to this, including readily available classes such as this one which basically does what you want. You may need to remove the parts for the shrinking text and so forth, but it's right where you need it
You need to place your RelativeLayout inside the ScrollView and try setTranslationY again - it should work

Categories

Resources