I am building an app that uses this library:https://github.com/umano/AndroidSlidingUpPanel to create a panel that slides on from the bottom of the screen when a user clicks an item in a listview.
However i dont want the slide up panel to take up the entire screen. I need there to be a gap at the top, between the panel and the action bar, of exactly 80dp.
I have tried everything i can think of (putting a spacer there with a transparant background, using layoutParams (gives error), etc). But nothing seems to work.
If someone could give me some suggestions as to what i could try next, i would much appreciate it.
The xml layouts are below.
Thanks for your time.
Corey
<com.bacon.corey.audiotimeshift.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="68dp"
sothree:shadowHeight="4dp"
sothree:overlay="true">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:id="#+id/fabbutton"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:colour="#color/holo_red_light"
app:drawable="#drawable/ic_content_new"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:textSize="16sp"
android:id="#+id/slideUpPanel"
android:background="#android:color/transparent"
>
<fragment android:name="com.bacon.corey.audiotimeshift.PlayFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_play"
/>
</FrameLayout>
</com.bacon.corey.audiotimeshift.SlidingUpPanelLayout>
What about wrapping your SlidingUpPanelLayout in another layout, say FrameLayout and adding some good old paddingTop to the latter?
I have found a workaround. Draw the background of the pane transparent and put a padding top, but first the library must be modified like it's written here:
https://github.com/umano/AndroidSlidingUpPanel/issues/4
Hope this helps somebody in the future :)
Related
I am a new user in Android dev. Actually I have one problem that I can't solve for much time.
I have a layout with Scroll View, there are ImageView and TextView in this ScrollView. You can see it in my code:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity ="center"
android:fillViewport="true"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:padding="10dp"/>
<TextView
android:id="#+id/textInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I take the data from JSON and using this layout for input it in.
There are images that have different forms.
So, please, help me with it. What I must to do with layout markup and what scaleType I must to use.
Thanks in advance.
P.S. Sorry for my English)
It would be helpful if you posted the code that takes the data from a json too.
For picking the right scaletype, this might help.
Hello) I have already solve my problem. I need only to add this things
android:scaleType="fitCenter"
android:adjustViewBounds="true"
I just forgot what adjustViewBounds do)
As you can see on the upper image, there are align options "to RightOf=button", "below=button" when you drag something, but when I drag something nothing like that is shown. Can anyone help me fix that?
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:id="#+id/text_witaj_uzytkowniku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/witaj_uzytkowniku" />
</RelativeLayout>
Honestly, I prefer to use ConstraintLayout as the root. I believe it is much easier to use with the drag and drop tool.
When using it make sure that all objects are connected to each other(or the parent) at least once vertically and once horizontally.
How this looks in the code:
<androidx.constraintlayout.widget.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">
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="#+id/textView9"
app:layout_constraintTop_toBottomOf="#+id/textView9" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can also adjust the distances using the side panel.
To use the layout you just need to type Constraint layout in the Pallete and drag it (if it is not installed, there will be a download)
Set position of your textview then try to add another view by dragging
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:id="#+id/text_witaj_uzytkowniku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop ="true"
android:layout_alignParentLeft="true"
android:text="#string/witaj_uzytkowniku" />
</RelativeLayout>
I think instead of Relativelayout, you should use the CoordinatorLayout.
And if you continue with Relativelayout then go to file invalidate and restart your Android studio if this is cache related issue then resolved it.
Use Coordinator Layout to work. RelativeLayout is more of coding layout..
I have a view which contains a top view (it's a mapview but it's not implemented yet) and a listview below it.
What I'm trying to do is to make the top of listview to be overlay the bottom of the top view a little bit. Here is something similar to what I'm trying to achieve :
(without the tab headers and the image will be the mapview)
I'm not sure how I can achieve that, here is what I have so far:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#android:color/holo_red_dark">
</View>
<com.hmm.widgets.CustomListView
android:id="#+id/runners_list"
android:background="#android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="10dp"
android:divider="#android:color/darker_gray">
</com.hmm.widgets.CustomListView>
</RelativeLayout>
I've tried negative margin which didn't work. I'm not sure how can I achieve something similar. Should I be using FrameLayout?
You can use LinearLayout in your case and design the layout like this. This is a trick of setting a negative layout_marginTop to your custom ListView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<View
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#android:color/holo_red_dark">
</View>
<com.hmm.widgets.CustomListView
android:id="#+id/runners_list"
android:background="#android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:layout_marginRight="#dimen/activity_vertical_margin"
android:dividerHeight="10dp"
android:layout_marginTop="-40dp"
android:divider="#android:color/darker_gray">
</com.hmm.widgets.CustomListView>
</LinearLayout>
Complementing Reaz's answer, you can do it with RelativeLayout too without using negative margins (which are a bit controversial).
Note the last four attributes in the CustomListView: you constraint the height with alignParent*, set a dummy height which will be discarded, and offset the view from the top with a margin. The "negative offset" will be 250dp - 200dp = 50 dp.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#android:color/holo_red_dark">
</View>
<com.hmm.widgets.CustomListView
android:id="#+id/runners_list"
android:background="#android:color/darker_gray"
android:layout_width="match_parent"
android:dividerHeight="10dp"
android:divider="#android:color/darker_gray"
android:layout_height="0dp"
android:layout_marginTop="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true">
</com.hmm.widgets.CustomListView>
</RelativeLayout>
im making a launcher app. in the tutorial it uses a Sliding Drawer which deprecated in Api 17. what could i use instead of this? i tried using the Slideup Panel from one of the posts on here link Below to the gitHub below
gitHubLinkhttps://github.com/umano/AndroidSlidingUpPanel
. but it wont allow me to use it in the way i want. i want the apps to appear in the drawer not in the main content. for some reason the second view only allows me to create a Text view which is for the handle to slide it up. any advice on what other methods i could implment to do the same job. it must slide up from the bottom. thanks for all the help
Ok guys Sussed it. Using The GitHub I posted in the question. what it did is because im aloud as many layouts as i like but only 2 children. i used a relative layout as my first layout with a gridView for my homescreen apps inside and closed it off. then i used anther Relative Layout Below with a textview inside then another Relative layout set with 80dp Padding at the top (the Size of my Text Handle) inside this one i had another gridview for my apps and closed it all off.
the Xml for it looks like this
<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" tools:context=".MainActivity"
android:id="#+id/Mainlayout"
>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="80sp"
sothree:umanoShadowHeight="4dp"
sothree:umanoDragView ="#+id/dragView"
sothree:umanoScrollableView="#+id/list"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content1"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:clickable="true"
>
</GridView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/handle"
android:text="b"
android:textSize="80sp"
android:textColor="#17ff1c"
android:gravity="center|top"
android:clickable="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="80sp"
android:id="#+id/dragView"
android:clickable="true"
android:focusable="false">
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="80sp"
android:id="#+id/content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:gravity="center"
>
</GridView>
</RelativeLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
I trying to create a relative layout that look like toolbar but I keep on having such height problem as shown below:
What I want is:
Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/Searchtoolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="#color/Toolbar_default_color"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_below="#+id/Searchtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/FilterLayout"
android:layout_width="match_parent"
android:layout_height="40dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/search_filter_icon"
android:background="#drawable/search_filter_bgn_btn"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<ListView
android:id="#+id/feed_listview"
android:layout_below="#+id/FilterLayout"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null" />
</RelativeLayout>
</RelativeLayout>
In your ImageButton use: android:layout_height="match_parent"
instead of android:layout_height="wrap_content"
Or resize your Image using photoshop or any other free tool to fit 40dp exactly.
WRAP_CONTENT: which means that the view wants to be just big enough to enclose its content (plus padding)
What you need:
MATCH_PARENT: which means that the view wants to be as big as its parent (minus padding)
Documentation.
I found my bad and silly mistake. It was the "android:layout_marginTop="?attr/actionBarSize" under the listview that causes the white layout to be extended. After I removed that line, I got what I wanted. =)