Having trouble with the umano android slidinguppanel 2 views as sliding child - java

I am using this library from umanoAndroidSlidingUpPanel and it works fine theres just a problem I cant fix.
the main child is a mapview (static main view) that is working fine and the second child (the slidinguppanel) is a responsive html file in a webview and an imageview.
the problem is that when I swipe up to slide the panel i cant scroll the html file inside the webview.
the library states that I can make a single view draggable so that I can scroll the other but i really dont know how to do it help would be really appreciated.
heres my xml file
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="50dp"
sothree:shadowHeight="4dp">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/llayout"
android:orientation="vertical"
android:layout_height="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity ="center_horizontal"
android:src="#drawable/divider">
</ImageView>
<WebView
android:layout_width="match_parent"
android:id="#+id/desc"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="7dp"/>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

I fixed it I just had to call the library method for setting the dragview and set only the imageview as draggable so the webview would scroll normally,
heres how I did it:
ImageView image=(ImageView)findViewById(R.id.divideri); //Layout to slide
SlidingUpPanelLayout layout = (SlidingUpPanelLayout)
findViewById(R.id.sliding_layout);
layout.setDragView(image);
Over and out ...

Related

Imageview stucked at the top of android layout

I have put two linear layouts, under the first linear layout I have put the "textview" and In the second one I have put "imageview". But the problem is that image view is not moving, I want that dice icon in the centre. Whenever I try to drag that icon it gets stucked at the top left corner of the layout.
I can't figure out what's going wrong as I am new to android.
Have a look at the screenshot
https://i.stack.imgur.com/SJmEY.png
activity_main.xml
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/Logo"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="36sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/five" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.snakes;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
You cannot drag elements in a LinearLayout. They are placed in the order they are declared in the layout file, depending on the orientation set (either horizontally or vertically).
There is also no reason to have two linear layouts like this in your case. You can place both of your elements inside of the first one, and use the gravity property to center the image view (ex. gravity = "center_vertical").
EDIT:
I ended up trying it myself, and resolved it using a RelativeLayout inside a LinearLayout. Make sure the RelativeLayout matches the parents width and height, then center the ImageView inside of the RelativeLayout, like so:
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/someImage"
android:orientation="vertical"
android:layout_centerInParent="true"/>
</RelativeLayout>
</LinearLayout>
You need to add to the second linear layout - constraints statements. I can't recall the exact name of them but I think It's something like "layout_constraintTop_toBottomOf". this should make them constraint. then if you want you can determine the gap and adjust the view.

Center ProgressBar inside RecyclerView that is inside ConstraintLayout

I have a ProgressBar that is an item of the RecyclerView and was added there with the adapter following this tutorial Android RecyclerView dynamically load more items when scroll to end with bottom ProgressBar.
But instead of using a RelativeLayout in the activity_main.xml file, I'm using the default ConstraintLayout. The problem for me is that the ProgressBar isn't centered.
Please find below the layouts I've described above:
The progress bar item
<?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="vertical">
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
The activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="me.bookquotes.quotes.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Below is a screenshot of the ProgressBar that appears on the left (I need it to be centered):
I've taken a closer look at your issue and it is not clear at all what is going on. I have taken the sample project and applied your changes to the layouts and it works just fine. (I did remove a tools reference and changed a couple of ids.)
Here is the GitHub project with the changes just to the two layouts above. Here is a video of this modified app that shows the progress bar in the center as expected.
I was thinking that this was a constraint issue but, as you can see from the demo, that is not the case.
It is also possible that this may be related to the version of ConstraintLayout you are running or some other configuration thing, so you may want to check that out. Otherwise, it looks like something else is going on that has not been revealed. Are you doing any other manipulation of the layout widgets?
It would be useful to know what in your layout is not lining up. Give the LinearLayout a background color to see if it stretching across the screen or not. That will tell you if the progress bar is misaligned or whether the LinearLayout is pinched.
One other possibility: Are you failing to name the parent in the inflation of the LinearLayout? Say something like this:
View view = LayoutInflater.from(activity).inflate(R.layout.item_loading, null, false);
instead of this
View view = LayoutInflater.from(activity).inflate(R.layout.item_loading, parent, false);
That small difference will shove your progress bar to the side.
You need to add gravity to your parent LinearLayout which sets the child's gravity to center.I have corrected the progressbar layout.
Hope this could help.
<?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:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Are you trying to center in middle of screen ?
Or just inside the linear layout
Try gravity instead of layout gravity which will try to center inside the linear layout instead of constraint layout. Since you already have match parent width on it . Also post code to show when you are adding the progress bar to the view .

Why does ScrollView doesn't scroll even if it has text to show

I'm strugglingwith ScrollView, and don't really see what's wrong with it.
-My objective is to make a scrollable fragment with images and text(under each image). I've already added some simple images, and was trying to add a dedicated ScrollView for text under those images.
Problem explanation starts here:
When the fragment has only 1 image and 1 ScrollView the ScrollView work fine, but when I add one more image below, ScrollView just freezes and doesn't scroll anymore. Where is my mistake?
Here is the code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout
android:id="#+id/LinearLayout_Parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/top_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image1"
android:adjustViewBounds="true"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="100dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/rly_large"/>
</ScrollView>
//when ImageView is added ScrollView stops wotking
**<ImageView
android:id="#+id/top_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image2"/>**
</LinearLayout>
Whitout ImageView inside ** everything works fine but when that ImageView is added the ScrollView stops scrolling.
I hope you could point for the mistake, and hope didn't made a stupid question.
Thank you very much.
Android Stuido: 2.1.2
JRE 1.8.0-b15
Having a ScrollView inside another ScrollView is not a good practice. However the code you have used could work in some cases. But it might fail when you are having multiple elements. In that case, it might not be able to identify the gesture.
However, you can try this answer, if it helps ScrollView Inside ScrollView. It disables the parent ScrollView's touch, when a touch for the child is identified. Also have a look at this post if it helps.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout
android:id="#+id/LinearLayout_Parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/top_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image1"
android:adjustViewBounds="true"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="100dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/rly_large"/>
</ScrollView>
<ImageView
android:id="#+id/top_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image2"/>
</LinearLayout>
You are using ScrollView as root element but never add the close tag.
(that might be a copy-paste problem)
Additionally, using ScrollView as root element causes problems in my experience, so if you push the ScrollView that currently is a root element one layer in and set LinearLayout as root element, that may solve your problems.
Additionally:
Whitout ImageView inside ** everything works fine but when that ImageView is added the ScrollView stops scrolling.
is a little hard to understand. Which of the two stops scrolling?

How to make Horizontally scrollable Grid View?

I am trying to make a Grid View and it has a lot of images. So I want to make it Horizontally scrollable, but it is not scrolling. How to make Horizontally scrollable Grid View ? Please help me.
Here is my code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="horizontal" >
<GridView
android:layout_width="500dp"
android:layout_height="400dp"
android:id="#+id/gridview"
android:columnWidth="300dp"
android:numColumns="3"
android:horizontalSpacing="10dp"
android:scrollbars="horizontal">
</GridView>
</HorizontalScrollView>
</RelativeLayout>
I got the answer, and I am sharing here.
Just go on the following link:-
Link and just add this library into your project. After that just use the xml code at the place of Grid View code.
<com.jess.ui.TwoWayGridView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/grid_viewlevel"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:gravity="center"
app:columnWidth="200dp"
app:rowHeight="200dp"
app:numColumns="15"
app:numRows="2"
app:verticalSpacing="0dp"
app:horizontalSpacing="0dp"
app:stretchMode="columnWidth"
app:scrollDirectionPortrait="horizontal"
app:scrollDirectionLandscape="horizontal"/>
After normally Just apply the following code in your java file.
TwoWayGridView scrollview;
scrollview = (TwoWayGridView) findViewById(R.id.grid_viewlevel);
mAdapter = new LevelAdapter(this, R.layout.levelselect);
scrollview.setAdapter(mAdapter);

HorizontalScrollView swipe/fling guesture listener

I know this is a common question , but I am completely messed with those different examples and tutorials available on the web.
I have a horizontalScrollView where I add some view dynamically , and I want to set a guestureListener for swiping through the Views . Each view's with is equal to the width of the screen.
You can use the View Pager instead of the horizontalScrollView. http://developer.android.com/reference/android/support/v4/view/ViewPager.html
To keep the View pager at half the screen use something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5">
<android.support.v4.view.ViewPager
android:id="#+id/pagerPromo"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicatorPromo"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical">
This View Pager has a circle indicator at the bottom but you can remove that if you like. Just play around with the weights and see what works best for you.

Categories