开发者

Android Visual Tree Information

I am not sure if the terminology is correct, but I am looking for informations about the visual tree used by android to render stuff. The background is simple, I just started developing and had a problem with the TabHost. I solved it, using the code y开发者_开发问答ou can see at the end of this post.

The reason for my question, I still don't really know which other properties or children are available, and this will sure be the case for other controls.

So which is the best way to find out that e.g. the TabWidget has a child at position 0, which has layout params, where i can set the height (just an example). Besides http://developer.android.com/reference/android/widget/TabHost.html

        tabHost.setCurrentTab(2);

        tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 60;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 60;
        tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 60;


            // Bump the text size up
            LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
            android.widget.TabWidget tw = (android.widget.TabWidget) ll.getChildAt(0);
        {
            RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);
            TextView lf = (TextView) rllf.getChildAt(1);
            lf.setTextSize(20);
        }

        {
            RelativeLayout rllf = (RelativeLayout) tw.getChildAt(1);
            TextView lf = (TextView) rllf.getChildAt(1);
            lf.setTextSize(20);
        }

        {
            RelativeLayout rllf = (RelativeLayout) tw.getChildAt(2);
            TextView lf = (TextView) rllf.getChildAt(1);
            lf.setTextSize(20);
        }


Besides the online documentation on View and its subclasses, which include the all properties on a view available to modify in XML/code, you can use Hierarchyviewer to inspect layouts on the fly.

Also, as far as your code goes, instead of creating tabs and then modifying them in code, you could have also used TabSpec.setIndicator to just set a custom layout for the tab.


You might like to try running the hierarchyviewer.bat in the tools folder. This gives you a visual tree/hierarchy view and shows you the properties of each element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜