2

I want to make UI for tablet like shown in images.This UI will repeat according to number of items. And the position of each block (i.e small or big block) can change dynamically. Please give me suggestion which view,layout i should use. Any suggestion would be appreciated...thanks in advance.

enter image description here

6 Answers 6

2

If you are targeting a API v14 or above, you can use GridLayout: http://developer.android.com/reference/android/widget/GridLayout.html

Sign up to request clarification or add additional context in comments.

3 Comments

My app minSdkVersion is 8. Any other option...?
Hey @evaristokbza Please check updated image and give your valuable suggestions.
I´ve never used it, but you can use the GridLayout from the support libary v7: developer.android.com/reference/android/support/v7/widget/… (for that you have to include that support library in your project; guess you know how to do it).
1

Using LinearLayout where each category is added and using RelativeLayout for each category is a good option. You should customize onlayout method of the relative layout as a function of number of products it contains.

You can use fragments, listview as well.

EDIT after image change: You can just extend relativelayout and override onLayout method. This will perform better than nested layouts and I can't think of anything else you can get away with less effort.

EDIT for elaboration:

Here is an example class I use. Basically in the onlayout method you make every decision and tell all the child views to lay them in a rectangle by calling layout method of each of them and passing the parameters of the rectangle. See how I use layout method of child view to dictate the rectangle.

public class KnockPile extends  HandPile
{

private static final String TAG = "KnockPile";

static final int EXPECTED_CARDS = 3;

int mColoring; // this is the coloring group this pile is associated with.
// every card added to this pile should be set with this color.


public KnockPile(Context context, GameActivity ref , int ingroup)
{
    super(context );
    mColoring = ingroup;
    mActivityReference = ref;

    setWillNotDraw(false);
    setClickable(true);
    setOnDragListener(this);
    mCardBorders = new ArrayList<Integer>(); 

    final LayoutTransition transition  = new LayoutTransition();
    setLayoutTransition(transition );
    //transition .enableTransitionType(LayoutTransition.CHANGING);
    //transition .disableTransitionType(LayoutTransition.CHANGE_APPEARING);

}



/**
 * this overrides the card ordering of handpile. This method lays the cards in a linear fashion.
 * Possibly overlapping fashion. This is not dependent to orientation of screen.
 *
 * @see com.kavhe.kondi.gin.layouts.HandPile#onLayout(boolean, int, int, int, int)
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {   


    int availablewidth = getMeasuredWidth() ;//this is the maximum availlable  
    int distance = availablewidth /Math.max(getChildCount(), 1) ; // the horizontal distance between two cards
    Log.v(TAG,"available width onlayout is :" + availablewidth +"and distance is  " + distance);
    int cardheight = getHeight();
    int cardwidth  = cardheight*3/4; 
    if(distance > cardwidth) distance = cardwidth;
    mCardBorders.clear();
    for(int i = 0 ; i < mCards.size() ; i++)
    {     
        //save this border into a global variable so that it can be used when one of the cards dragged
        //by user to show that user can insert to that location
        mCardBorders.add( i*distance);
        mCards.get(i).layout(  i*distance ,  0 , cardwidth+ i*distance ,   cardheight); 
    }

}
}

and this is from documentation

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters

changed This is a new size or position for this view

left Left position, relative to parent

top Top position, relative to parent

right Right position, relative to parent

bottom Bottom position, relative to parent

3 Comments

Edited after image change.
Can u just elaborate your answer by giving an example?.I don't know how to write onLayout method(). I am very much new android programming. And I think that I will get some possible way from your answer. Thanks in advance.
I added some code; it contains more but you may get the idea on onLayout method.
1

It is also possible through table layout with its row span property

Comments

0

Are the "products" always going to fit nicely on lines as you have drawn? If then, you can use LinearLayouts (Vertical and Horizontal) nested in each other.

2 Comments

Using LinearLayout it is anyhow not possible. I tried it lot. Please check image once again. I have edited it.
The layout could be achieved as: VERTICAL (HORIZONTAL (1, VERTICAL(2,4), VERTICAL(3,5)) , HORIZONTAL( VERTICAL(6,7), 8, 9), HORIZONTAL(10,11,12))
0

To design such UIs for Tablets you should use Fragments and inside the fragment add/remove your respective layouts. If you are taking Relative Layouts then proper usage of RelativeLayout.LayoutParams is required.

If you are looking for a best example which uses Fragments try Google IO app source. It uses various dynamic UI features.

Hope it helps !

1 Comment

Hi,As u said I am using fragment and tried a lot using relativelayout but it is very much problematic. please check the updated image.
0

With the help of StaggeredGridView I sloved my requirement. Thanks to all for help and support.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.