I want to implement scrollable tabs in my app.
I have some content like image, some text views to show the information of the page and a viewpager that is showing the tabs at the bottom.
My problem with the viewpager is, the content keeps loading at that same place whenever I slide or click on any tab.
What I want is that:
the swipe of the tabs should be disabled and only click event should work on the tabs like buttons.
whenever I click on any tab that fragment should load in the full
page, like an activity.
How can I achieve this?
My layout xml is:
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="match_parent" android:layout_height="200dp">
</com.android.volley.toolbox.NetworkImageView>
</RelativeLayout>
</LinearLayout>
Related
I haven't developed for Android in more than a year and I'm a bit rusty with it. I'm trying to setup a kinda simple UI: a bottom bar at the bottom of the screen and a fragment above it (but without filling the whole height). Something like this:
I thought this would be quite simple, but after a while struggling with it I can't manage to make it work without some "hacks".
The bottom bar is also implemented as a Fragment. This is my XML:
<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" >
<fragment
android:id="#+id/bottomBar"
android:name="com.mytestpackage.BottomBarFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottomBar"
android:layout_alignParentBottom="true" />
</RelativeLayout>
The Fragment in fragmentContainer is dynamically loaded from code. With the code paste above, fragmentContainer is aligned bottom but it's not above bottom bar, they're overlapped. If I remove the alignParentBottom from fragmentContainer, then it's placed in top of the screen.
Like I said, I found two "hacks" to solve it but I don't like them much:
1- Set a padding/margin bottom to fragmentContainer.
2- Use a filler empty layout on top of the screen and set fragmentContainer to be below that one.
Is there any way to achieve the layout I want without having to use some tricks like the ones I said?
Thanks!
Add to the relative layout:
android:gravity="bottom"
Ah, and android:orientation="vertical" is meaningless for RelativeLayout
A simpler solution would be to use a LinearLayout with vertical orientation and gravity bottom instead of the RelativeLayout.
I use the Drawer Layout in my project. I want to customize the Drawer like the Google+ Android App. Over the "main" ListView I've added a ImageView. That's work fine. The code is:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="#+id/drawer_layout_relative"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="start" >
<ImageView
android:id="#+id/drawer_header_image"
android:layout_width="wrap_content"
android:layout_height="85dp"
android:src="#drawable/ic_logo_blue" />
<ProgressBar
android:id="#+id/drawer_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/drawer_header_image"
android:background="#ffffffff" />
<ListView
android:id="#+id/drawer_listview"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_below="#id/drawer_progress"
android:background="#ffffffff"
android:choiceMode="singleChoice" />
</RelativeLayout>
When you click on one of the ListView-Items a fragment load into the FrameLayout. Thats work perfectly, too.
But there is one problem. The ImageView is "clickable" too. So that, when the Drawer is open, an one will click on the ImageView the ListView (on the fragment) behind is clicked!! I don't want that. So I have try it with clickable:false on ImageView. Don't work...
For a little demo here is a video: http://www.vidup.de/v/Ao71r/
How can i make the imageview don't clickable?!
In order to keep clicks from being passed through the drawer to the view behind it, you have to setClickable to true for the view in the drawer, specifically the parent view of all the other views you have in your drawer, so that it consumes all the touch events if none of its children consume them.
Change your RelativeLayout code for drawer_layout_relative to the following (NOTE: I added android:clickable="true" to the relative layout):
<RelativeLayout
android:id="#+id/drawer_layout_relative"
android:layout_width="240dp"
android:clickable="true"
android:layout_height="wrap_content"
android:layout_gravity="start" >
By default, if a view does not handle any clicks, it lets the clicks go to the view behind it. You have an ImageView, a ProgressBar, and a ListView: The ListView handles click events, so it consumes any touches on it. The ProgressBar and ImageViews by default just display stuff and don't handle clicks to them, so the system just passes the click to the list that you have behind the drawer. Those three views are all inside a RelativeLayout. If we set that RelativeLayout to be clickable, it collects the click events that aren't handled by the ImageView and ProgressBar and it doesn't let the click events go to the view underneath it.
Think of android:clickable="true" as a way to block interaction with any view underneath the view you set this on.
For further explanation, please see this question
I am using this LIBRARY for my slide up panel. every thing is working fine with a simple layout.
Now my question is , how can I insert a pager title strip in that panel so that I can make it my View pager working on it with multiple fragments.
First image is title strip at bottom
second is slide up and sliding fragments
From your previous post, I'm assuming you're using this library (https://github.com/umano/AndroidSlidingUpPanel).
This library requires that you have 2 children views. The first one being the main layout and the second one the actual sliding view. Now, your sliding view is just a placeholder, so you can place anything you want in there. If you want to add a ViewPager, this is how you can do it.
<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" >
<SlidingUpPanelLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Top Panel -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<!-- Sliding Panel -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
</SlidingUpPanelLayout>
</RelativeLayout>
What we have here is the main layout of our Activity (RelativeLayout) and we're adding the SlidingPanelLayout to it. Inside this Layout, we've defined our main layout to be a LinearLayout (Top Panel) and a second LinearLayout (Sliding Panel) which is the actual sliding view. Now, all we need to do is add a ViewPager to this sliding panel.
I am currently working on a prototype where I have two fragments in a LinearLayout.
Here is what the xml looks like:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/map_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="#id/footer"
android:layout_weight=".30"
>
</FrameLayout>
<FrameLayout
android:id="#+id/list_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="#id/footer"
android:layout_weight=".70"
>
</FrameLayout>
</LinearLayout>
The top fragment is a map fragment and the bottom fragment is just a list of items. I am trying to expand the map when the user clicks on the fragment. The height changes from .3 to 1. Currently I have tried to animate and change the height of the fragment, this gives horrible performance. I have looked around and found that Facebook Nearby Places does this effect smoothly. Should I be using the ScaleAnimation class to do this? Thank you for your help.
Edit:
Foursquare has the same type of effect. When click on the map it scales smoothly into fullscreen I have attached a screen shot.
Here is an example of what it looks like:
http://im.tech2.in.com/gallery/2013/apr/foursquareforandroid_041425247544_640x360.jpg
I am not sure how to do this? I want a static view at the bottom of another layout that the user can slide up to show another view. I'm not sure what this feature is called but I know the Facebook app does this and so does ESPN and Google plus. Thanks!
The simplest thing to use would be a SlidingDrawer.
As long as you want to slide up from the bottom (or the right) this will work beautifully. It doesn't work if you want to slide something down from the top or in from the left however.
To use it you just need something like this in your XML layout:
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:handle="#+id/handle"
android:content="#+id/content">
<ImageView
android:id="#id/handle"
android:layout_width="88dip"
android:layout_height="44dip" />
<GridView
android:id="#id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</SlidingDrawer>
Where the ImageView is the "handle" (the thing you drag up and down to open the drawer) and the GridView is the whatever content you want the drawer to hold (It can be any type of view, not just a GridView).