开发者

Custom Android view like the one that shows app in menus

My app ha开发者_Go百科s a lot of similar buttons with an image and title at its bottom. All I want is an easier way to do it so that I dont have to replicate views. Since it gets dirty in xml.

I believe I have to ways.

1) Using the include tag. But in this case how can I change the name of the child image and textview directly in the main screen where I am including this custom view. 2) Build a custom view with on Draw etc. Dont want to try this because it looks quite achievable from the last idea.

Thank you for your help.


You can use Buttons for this purpose. Set transparent background to it, your text and your image as drawableTop property.

Example from Google IO application:

<Button android:id="@+id/home_btn_schedule"
    style="@style/DashboardButton"
    android:text="@string/btn_schedule"
    android:drawableTop="@drawable/home_btn_schedule" />

Styles from this example is here.


i think include will do the job. basically when you include a view and set ids for its child view's you can just simply use findViewById() to get a reference to those views. includes act the same way as if you actually have the full xml. alternatively you can find its parent by id which would be something like LinearLayout lin = findViewById(R.id.linearLayout_ref) and then use lin.findViewById(R.id.myIncludedTextView) to get the reference to your view.

also don't forget to vote :D

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜