Custom Layout Tutorial for Android?

I am on my way trying to figure this out and hope there is someone who has a solution.

I want to create a custom layout for an Android application. This should theoretically be fairly straightforward, but I cannot find any useful information on how to do this.

I am looking for: 1) A simple, step-by-step tutorial on how to subclass ViewGroup to create custom layouts. 2) A basic understanding of internal mechanics, for example, how to access children's representations, how and when to ask a child's representations, how to draw oneself, how to define xml for a custom layout, how to access custom xml attributes, etc.

I looked all over the Internet, and I can only find small tidbits, and even could not start creating a subclass.

I found 1) The conversation listed at http://parleys.com/#id=2191&sl=3&st=5 , but after a few minutes it aborts the subscription request. 2) The API link to http://developer.android.com/reference/android/view/ViewGroup.html , but this does not give any idea of ​​how to realistically implement the subclass.

+3
source share
1 answer

I found this. It is hard for nothing.

Tutorial

There is no longer an absolute layout in android support. I just want to use the setX method. FrameLayout is the best option. See also: fooobar.com/questions/1821600 / ...

FrameLayout , . , :

// x y onCreate

// - // post ,

  VEIW_MAIN = (ViewGroup) findViewById(R.id.activity_main);

   VEIW_MAIN.post(new Runnable() {
            @Override
            public void run() {

                LayoutParams paraBigText = BigText.getLayoutParams();
                Double d24 = 200.0;
                paraBigText.width = d24.intValue();
                BigText.setLayoutParams(paraBigText);
                BigText.setGravity( Gravity.CENTER_HORIZONTAL);

           }
       });

...

ViewTreeObserver vto = SOME_ELEMENT.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()       
{
    public boolean onPreDraw() {

         // changes here
        return true;
    }
}); 

...

- , :

 if (EKRAN.WIDTH() <= 480)
            {
                FIX_FOR_480_WIDTH();
            }
            else if (EKRAN.WIDTH() == 540) {
                FIX_FOR_540_WIDTH();
            }
            else if (EKRAN.WIDTH() == 720) {
                FIX_FOR_720_WIDTH();
            }
            else if (EKRAN.WIDTH() == 1080) {
                FIX_FOR_1080_WIDTH();
            }

...

 void FIX_FOR_540_WIDTH()
    {
        System.out.println("FIX FUNCTION FOR 540 low width !!!!!!!");
        SOMEELEMENT.setY( 0.865f * EKRAN.HEIGHT() );
    }

...

SCREEN : - Android DisplayMetrics

, , canvas2d uniq UI...

+2

All Articles