what element type and layout for should I use for app landing page navigation buttons? - android-layout

I'm pretty new to Android Development, i'm following some Youtube tutorials currently. I'd like to create a basic mobile tourist application, but i'm stuck as to how to create the main menu layout.
Each Favorite 1 - 3, and Options 1 - 9 should be icons. (I'm not sure which form element should be used for this).
QuestionHow can I create the favorite, and option icons in the layout.xml file, what element is best suited, and what layout(s) should I use?
In HTML, i'd create a table with 3 columns, 4 rows and set the table width and height to be 100%, and make the td valign and align central.

Here you could make horizontal linearLayouts of vertical LineraLayouts of Image+TextView pairs.
The second range linear layouts would have
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
Inside second range layouts you could use for image and text/view:
...for images:
android:layout_width="match_parent"
android:layout_weight="3"
android:layout_height="0dp"
... for texts
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
And the screen is nicely divided.

Related

HorizontalGridView from lean back i want to keep item in center

I have list of item, i am using HorizontalGridView to display that item, i want to keep the HorizontalGridView in center of the screen but its not working.
Following is my code:
<android.support.v17.leanback.widget.HorizontalGridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_centerHorizontal="true"/>
But it occupies complete width and height even-though there is less item
Note: I am developing for android tv using leanback library
It's better to use RecyclerView if you want to center and wrap content. Actually, HorizontalGridView extends RecyclerView, so it will be easy to change to:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_centerHorizontal="true"/>

Adding Layout Weight dynamically

For my project I want 30 images in my page, and I want to arrange them in such a way that there are 3 images in one horizontal linear layout.
Since I cannot use density pixels as it may look different on different divices, I want to use layout_weights. The way we write in our XML files :
<ImageButton
android:id="#+id/my_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
**android:layout_weight="0.33"**
android:background="#android:color/transparent"
android:src="#drawable/ic_launcher" />
I want to know what will be the Exact Equivalent of the XML code in Java Language..
You can set the weight using the LayoutParams of your view (the last param)
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 1.0f);
myView.setLayoutParams(params);

RealPlayer like Android app layout

I am new to Android and I am trying to design my Android application like the interface of the Android RealPlayer but I have no idea how!
What I exactly want to design is: Break the page into 4 equal grid-like sections such that the whole page is covered and no extra empty space is left at the end of the page (exactly like the RealPlayer interface).
<?xml version="l.0" encoding="utf—8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android“
android:id=“#+id/gridview“
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_weight="l.0"
android:columnWidth="90dp"
android:horizontalSpacing="l0dp"
android:numColumns="2"
android:orientation="horizontal"
android:paddingTop="50dp"
android:stretchMode=“columnWidth"
android:verticalSpacing="l0dp" >
</GridView>
I have tried manipulating GridView attributes but it seems that it is not possible only using GridView elements. I hope my problem statement is clear enough! Can somebody give me a hint on how to do that?
I have found out that it is possible using buttons of different sizes!

Android - ListViews inside tableLayout

I'm trying to build and app that shows organized data so I'm thinking that basically a TableLayout would be a good idea, just to keep them in rows, so I'm wondering whats the correct way to do it? I have this in my xml
<?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="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/hello" >
</TextView>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="233dp"
android:layout_marginTop="44dp" >
</ListView>
</TableRow>
</TableLayout>
</LinearLayout>
then it's just that the TableLayout tag and TableRow tag displays a warning that says:
"This TableLayout layout or its LinearLayout parent is possibly useless"
so what I understand is that is not picking up the TableLayout. how can I fix this? is there another way to do this easly?
so what i understand is that is not picking up the tablelayout. how can i fix this? is there another way to do this easly?
Not quite, the renderer is taking account of the TableLayout but because the lint tool has detected that you have two views when you only need one (A LinearLayout and TableLayout) it is warning you that you should remove one of these layouts as it will boost performance while not effecting the functionality of the page.
I will add, you have a TableLayout with just a single row. TableLayout's are designed to allow their contents to format their columns based upon all of their rows. With a single Row the TableLayout & Row together are acting as a LinearLayout:
<LinearLayout>
<LinearLayout>
<ListView>
<TextView>
Since your TableLayout isn't adding any addition layout in that case it becomes obsolete and you will gain a resource boost from removing it and changing the orientation of LinearLayout to horizontal.
If you're planning to add more TableRow's later, then you should instead remove the LinearLayout for the same reason - it will then become the view which is not adding extra information: your table layout will be entirely responsible for the layout so you might as well make it the parent of the layout file (remember to add xmlns:android="http://schemas.android.com/apk/res/android" attribute to it if you do.)
In general I've seen the stronger warning:
This LinearLayout layout or its RelativeLayout parent is useless
when this is not the case. For example, this can happen if I've nested a linear layout inside a relative layout. The relative layout positions the linear layout exactly where I want it, the linear layout takes up space. Both are non-useless uses to me.
1) it says possibly so avoid drawing conclusions, trust yourself young padawan! But yes, the parent looks useless to me too :)
2) Using Table layout outside of your ListView wont change the rows' layout in the list, in case this is what you want to achieve.
You might have seen this but the Developers page offers a really good tutorial that can help you create a good base for your ListView (this example uses a ListActivity). Then on you can modify the rows' layouts using TableLayout ...etc.

Where is a reference to the android XML UI layout?

I am looking for a spec or reference of all the possible options for the various XML layout attribute settings that typically come with an android UI. Google seem to be good at burying it. This is similar to this question but remains in-effectively answered.
Such as what are my options available to me for the TextView layout_width definition ? There must be a complete definition published ... somehwere....
layout_* attributes aren't directly part of the view they appear on, which is why you won't find them in TextView's documentation. (TextView is not a ViewGroup.) They are arguments to the parent view, also known as LayoutParams. Take a look at the "Known Subclasses" sections at the top of the linked page for a list of them. They're instructions about how a ViewGroup should arrange each child view, and each parent type can recognize different ones depending on what kinds of layout options it supports.
For example, LinearLayout.LayoutParams supports the android:layout_weight parameter. Children of a LinearLayout can specify weight to request a proportion of the remaining space after all children have been measured. You can give equal weight to two sibling TextViews with a base width of 0 to give them each half of the available space within the parent.
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello" />
<TextView android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="World" />
</LinearLayout>
Normally developer.android.com is your site. Maybe this helps:
http://developer.android.com/reference/android/view/View.html
If you use Eclipse, then the autocomplete suggestions may help you as well in adding the right parameter.
...and the options you have for layout_width are
wrap_content (as large as the content of the View)
fill_parent (extends to the whole size - width or height - of its parent)
Layout parameters are pretty well described in the documentation for ViewGroup.LayoutParams and its subclasses. For the truly strong of heart, you can always browse the source for attr.xml.

Resources