I am working on an social networking app in android where I was using QuiltViewLibrary for making a QuiltView Gallery of images.
In the same application I have used the HANDMARKS Pull to Refresh library for the GridView.
Both are working fine. Now I have to implement both the libraries for the combined task, that is PULL TO REFRESH in QuiltView GALLERY.
The problem which I am getting is to combine the XML of both the LIBRARIES which are totally different.
XML for PullToRefresh with simple GRID VIEW:
<!-- The PullToRefreshGridView replaces a standard GridView widget. -->
<com.handmark.pulltorefresh.library.PullToRefreshGridView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/pull_refresh_grid"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:gravity="fill"
ptr:ptrMode="both"
ptr:ptrDrawable="#drawable/ic_launcher" />
</LinearLayout>
XML for QuiltView Gallery:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:quilt="http://schemas.android.com/apk/res/com.tv.photos"
android:id="#+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
<com.tv.photos.QuiltView
android:id="#+id/quilt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dip" >
</com.tv.photos.QuiltView>
</FrameLayout>
Please let me know if anyone can suggest me something.
This is quite simple:
Chris Banes' pulltorfresh library supports ScrollView
The QuiltView library is just an extension of a GridLayout (not GridView or any other adapter class)
Put an instance of QuiltView within an instance of PullToRefreshScrollView. Example java, xml.
Shouldn't be any more complicated than this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/pull_refresh_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.tv.photos.QuiltView
android:id="#+id/quilt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dip" />
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</LinearLayout>
You can continue to use handmark's pulltorefresh library and create a pulltorefresh view that works with quiltview inside it.
Since QuiltView extends FrameLayout, you cannot use it directly in handmark's pull to refresh, but you have 3 options in front of you:
1. Create new class of PullToRefreshQuiltView by extending PullToRefreshBase class.
Just create a class extending PullToRefreshBase
You can check PullToRefreshWebView class to get an idea of how to do that.
2. Use the scrollview in QuiltView's setup function
See line 50 of this link
You can either change the scrollview in setup function to a pullToRefreshScrollView, or add this scrollView to a ptr view.
3. Use RecyclerView with GridLayoutManager inside Handmark's PullToRefresh or android SwipeRefreshLayout
The other option is to use a RecyclerView with a GridLayoutManager ( Something that looks like GridLayoutManager Span Size RecycleView ) inside handmark's pulltorefresh or android's SwipeRefreshLayout.
For more information about SwipeRefreshLayout check the android docs.
Related
I have a scrollview that contain details of an item in my android app, what I need is to add a horizontal list of similar items (each inflate from a layout) at the end of this view. can anybody tell me how to do this?
P.S: I've tried Recyclerview and gridview and a library form this link but all of them are not working inside the scrollview !!!
Take a look at recent-images Library. It provides horizontal gridview(one row). Just add this library dependency and put below code in bottom of your scrollView.
<com.jess.ui.TwoWayGridView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#E8E8E8"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:columnWidth="70dp"
app:rowHeight="70dp"
app:numColumns="auto_fit"
app:numRows="auto_fit"
app:verticalSpacing="16dp"
app:horizontalSpacing="16dp"
app:gravity="center"/>
I've written an app and now want to design the UI. The problem is that I have the same data (well, not the same, but the same kind of data since it's an XML readout) and now I wanted to design it. But I don't think I can get the design how I want it programmatically. So I thought I design it once with XML and then copy the layout in the for loop for the other data as well. Is this possible?
If yes, how is it possible? I finished now my XML for one entry and now I want that all the other entries have the same style and layout as the others... Thanks!
There is simple way to achieve this.
There is include tag in xml file which you can use one layout in multiple screen design.
for eg. you had create header for application so no need to use same code in all file, just you can include that portion in each xml file.
here is simple example which may help you.
Create a Re-usable Layout
titlebar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:background="#color/titlebar_bg">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gafricalogo" />
</FrameLayout>
Use the Tag:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
You should be using an Adapter to define your ListView elements. In which case, you will define a layout for that adapter (using XML) that will apply to every element in your ListView.
Bottom line, use an Adapter, which will set the same XML layout for every element in your List.
(Check item #3)
http://docs.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters
I'm using in my project this library with custom ImageView which is able to handle pinch zoom and double tap zoom events: https://github.com/jasonpolites/gesture-imageview. I need to change in that library's source few things, because I want to use it with ViewPager. The problem is that the when I modifying source code of custom view in library and after this I adding this modified custom view to layout in XML file like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gesture-image="http://schemas.polites.com/android"
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<com.polites.android.GestureImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
gesture-image:min-scale="0.75"
gesture-image:max-scale="10.0"
android:src="#drawable/image"/>
</LinearLayout>
my changes don't want to appear, I'm breaking source code (for testing) by changing all values from 0 to 100, when I creating layout programatically my changes appears, and custom view works as i assumed, but when I definie layout in XML there's no effect, even if I clean up some java files of library from source code custom view in XML layout still works like there's no change in source.
Have you tried Project => Clean of both your main project and the library?
I have 5 unique pages of xml that are fairly complex. I want to put the 5 pages inside a ViewPager. All of the samples I can find simply put identical contents in each page via code. I want to declaratively define the xml in the viewpager like the xml pasted below. But this does not work - the app stops with this xml.
If I can't declaratively define it, then can I load individual xml pages into the viewpager? I can find no examples that do this.
thanks,
Gary Blakely
<?xml version="1.0" encoding="utf-8"?>
<fragment >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="#+id/imageView1"
android:src="#drawable/flashright" android:adjustViewBounds="true" android:scaleType="fitXY">
</ImageView>
</LinearLayout>
</fragment>
<fragment >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="#+id/imageView1"
android:src="#drawable/flashleft" android:adjustViewBounds="true" android:scaleType="fitXY">
</ImageView>
</LinearLayout>
</fragment>
If I follow, you want to declare everything in XML and avoid any programmatic initialization from within your Activity containing the ViewPager. The only way I can think of doing this would be to define 3 different Fragment classes which reference 3 different xml layouts. You could then embed them in your above xml, replacing each <Fragment> element with <FragmentX> <FragmentY> <FragmentZ> etc. Personally, I would rather write 3 xml layouts and create a single Fragment implementation that takes a single int argument to designate which layout to load, and then do the small amount of programmatic initialization necessary to make such a solution work. The rationale being that there is less duplicated code.
EDIT:
Another approach that might more fully address your requirements is to replace your <Fragment> tags with <Layout> tags and give them id's. Then in your Activity code, store refs to them, remove them from the View in onCreate() and finally add each of the stored references into programmatically created instances of Fragment which you then add to your ViewPager. Very ugly but thats the only way I know of to declaratively define everything in XML. You'll still have the problem that its not clear from the XML that these elements are nested within a ViewPager so personally I don't see the point. ListView and ListFragment operate with the same kind of implicit association though so its not unprecedented.
I'm making a custom view which contains an ExpandableListView, a CheckedTextView and a ListView :
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/filtersDialogView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="200dp"
android:orientation="vertical" >
<ExpandableListView
android:id="#+id/filtersListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<CheckedTextView
android:id="#+id/onlyShowAvailableItemsCheckedTextView"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:text="#string/OnlyShowAvailableItems" />
<ListView
android:id="#+id/categoriesListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The problem is that the CheckTextView is fixed and the two lists are scrolling independently (which is normal for that layout). Furthermore when I expand a list item from the ExpandableListView, the CheckedTextView and the other ListView become hidden. I'd like to make a single list with all these elements that could scroll and resize properly when I expand an element of the first list (the cells of the second list are not expandable). How can I do that? Is it possible to make it without having to modify the Adapters of the lists and the controller of the CheckedTextView ?
Thanks
How can I do that? Is it possible to make it without having to modify
the Adapters of the lists and the controller of the CheckedTextView ?
I doubt that, especially as you have two scrolling views, the ExpandableListView and the ListView. I think your only option is a special adapter that will simulate the layout above. I had a custom ExpandableListView adapter that I modified into something that will simulate the layout like the one above. It's something raw so there could be some errors(I've tested it a little) and of course there are other things to work on. The code sample it's a little big so I put it here https://gist.github.com/3046887 .