I Want to create an item list like PlayStore - android

I am trying to make an app for android and need the First page view to be like playstore. It should be showing some items.
How can I make the app look like this.
Like what kind of Adapter I can use.
I Googled a lot but couldn't find the answer. Any type of help will appreciated.
Even if you have any resource link it will be fine.

You can create the same by creating custom GridView.
Here is the link for the same.
Just change from this:
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:numColumns="3" >
to this:
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:numColumns="2" >
If you want two columns.

"Grid Style List" is possible with RecyclerView.
RecyclerView yourRecyclerView;//make your RecylclerView
YourRecyclerViewAdapter mAdapter;//make your adapter with extends RecyclerView.Adapter<YourRecyclerViewAdapter.YourViewHolder>
mGridLayoutManager = new GridLayoutManager(mContext,2);
yourRecyclerView.setLayoutManager(mGridLayoutManager);
yourRecyclerView.setAdapter(mAdapter);

https://www.caveofprogramming.com/guest-posts/custom-gridview-with-imageview-and-textview-in-android.html
take gridview with android:numColumns="2" and in adapter set your all content as per your need

Related

A way to Wrap LinearLayout

I have been trying to find a solution for this for weeks and keep putting this on my backlist, I am unable to wrap the height of a LinearLayout.
I have a simple LinearLayout
<LinearLayout
android:id="#+id/tagsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:padding="5dp"/>
Then I am adding multiple TextViews using my code into that LinearLayout with Tags Link style
Txt.SetBackgroundResource(Resource.Drawable.roundtext);
Txt.SetPadding(30, 10, 30, 10);
Txt.SetTextColor(global::Android.Graphics.Color.ParseColor("#373944"));
Txt.SetTextSize(Android.Util.ComplexUnitType.Dip, 12);
The results are the following
See the last TextView never goes to the next line
I looked up so many threads and solutions and it turns out that LinearLayout cannot Wrap contents like this Instead I will have to create my own Layout such as FlowLayout
Is there any simple solution to this problem?
You can use GridView instead of LinearLayout.
<GridView
android:id="#+id/tagsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"/>
This should automatically put the TextView to next line. If you want something more dynamic then you use FlowLayout library or StaggeredLayout.Check out this SO which claims that it has alternative to FlowLayout.
Take a look at flexbox-layout.
Easy to use and import with Gradle.

Android ListView - first element not centered vertically

As you can see from the screenshot below, the first item in the listview isnt centered vertically. How can I center it?
Activity XML
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/button"
android:layout_alignParentTop="true" />
Code, I'm just populating the listview from books array...
List<String> books = new ArrayList<String>();
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(Main.this, android.R.layout.simple_list_item_1, books);
lvFirst.setAdapter(adapter1);
Try adding this line to your ListView XML:
android:gravity="center"
It should look like this:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/button"
android:layout_alignParentTop="true"
android:gravity="center"/>
EDIT:
Sorry, now I understood your issue.
You're using "android.R.layout.simple_list_item_1" as your built in layout, but it won't work that way.
This is a duplicate of this question.
Just summing it up, you need to create your own layout to pass to the adapter. The answer is in the question link posted above.
Thank you for your time and answers, but I couldnt believe that that it was that bad of an implementation so I just listed some default layouts and this fixed my issue, so I want to write it here to help someone in the future.
adapter1 = new ArrayAdapter<String>(Main.this, android.R.layout.simple_selectable_list_item, books);
I just changed:
android.R.layout.simple_list_item_1
to:
android.R.layout.simple_selectable_list_item

Simple way to create display a few dozen icons?

In my app, I want to have some activities that display a series of small images, I'm aiming for 3 per row in portrait and 5 in landscape, but I'm not rigid about those numbers.
The first problem is, I can't figure out a layout, or a configuration of a layout that will allow me to achieve this effect properly. I've tried TableLayout, FrameLayout and RelativeLayouts, but none of them make my images look nicely arranged in both orientations.
In this case the images are flags. I've tried creating 9 Patches out of the ones with symbols in the middle which I don't want to be distorted. Android Studio doesn't pick up that they are .9 files. But that is a separate issue.
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/iceland"
android:layout_weight="0.25"
android:scaleType="fitXY"
android:id="#+id/imageView"/>
I made a mockup of what I'm trying to achieve. I'd really really appreciate any tips you guys can offer. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="50dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
taken from this link should deliver an example, that could be useful to you.

Simple non interactive ListView Android

Please cope with me as im new to android and i have done a lot of searching on my own, about this, and im fed up not finding a proper way.
This is my custom listview template. rowbuttonlayout.xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="19.6dp" >
</TextView>
<CheckBox
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3.6dp"
android:layout_marginRight="9.6dp" >
</CheckBox>
<TextView
android:id="#+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/check"
android:layout_alignBottom="#+id/check"
android:layout_toLeftOf="#+id/check"
android:text="#string/nothing" />
</RelativeLayout>
What i want is to create something like this in this pic without the header and footer.
http://www.vogella.com/articles/AndroidListView/images/xinteractive10.png.pagespeed.ic.V0cVgp99SN.png
As on my layout ill be having another textview just before the checkbox as well. Also ill be adding a dynamic button at the footer.
Now i dont want the users to interact with my listview. Only the button should be clickable and when they click it i want to run some calculations and show them in the relevant "result" textview and to check the checkbox next to it to show that i have calculated it. Meaning i have to access each and every "result" textview and "check" checkbox in the code.
Please provide me some guidance for coding this app. Im fed up looking through very complex codes trying learn on my own. Many many thanks for your help.
Shavinka
Check out below links...
ListView + CheckBox =?
How to get checked items from android listview?
http://sunil-android.blogspot.in/2013/04/android-listview-checkbox-example.html
http://fundoocode.net/android-listview-checkbox-example-onitemclicklistener-and-onclicklistener/
http://www.mysamplecode.com/2012/07/android-listview-checkbox-example.html

set size of android.R.layout.simple_dropdown_item_1line

I am new to android and I made an auto - complete textview and it is working , but my problem is the text size in the android.R.layout.simple_dropdown_item_1line is bigger than simple_dropdown_item_1line .
So is there a way that I can set the text size or set the size of the android.R.layout.simple_dropdown_item_1line ? .
Thanks in advance
Create a custom layout, or copy android.R.layout.simple_dropdown_item_1 contents create a new xml and pass this xml to AutoCompleteTextView
sample:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/autoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
/>
</LinearLayout>
srikanth gr's answer is outdated. This answer is best.
What is "android.R.layout.simple_list_item_1"?
A link to the file in github is:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_dropdown_item_1line.xml

Categories

Resources