开发者

Custom FrameLayout that adds items to sub FrameLayout?

I am trying to make some kind of button that can have content added to it like it is done to a FrameLayout. For example:

<ch.pboos.android.ui.ContentButton ...>
  <LinearLayout ...>
    <TextView .../>
    <TextView .../>
  </LinearLayout>
</ch.pboos.android.ui.ContentButton>

So far I made a view that xml file that would represent how i want the button to look like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="m开发者_C百科atch_parent" android:paddingLeft="@dimen/white_button_margin"
  android:paddingRight="@dimen/white_button_margin">
  <LinearLayout android:layout_width="match_parent"
      android:layout_height="wrap_content" android:orientation="horizontal"
      android:padding="@dimen/white_button_padding"
      android:background="@drawable/channel_bg">

    <FrameLayout android:id="@+id/content" ...>
      <!-- content -->
    </FrameLayout>
    <ImageView ... android:src="@drawable/right_triangle" />
  </LinearLayout>
</LinearLayout>

Now I would like to make a custom FrameLayout (ch.pboos.android.ui.ContentButton) that will add that view and allow me to add views into the content area of that xml above.

Any suggestions on how to get this working correctly?


1) Dispatch all touch events occurring on ContentButton to custom button via overriding dispatchTouchEvent. And add on click listener to this button (this helps you to recognize and handle only clicks, not e.g. moves)

2) override addView this way:

addView(...) {
   if(inflatingInProgress) {
      super.addView(view);         
   }
   else {
      // add view to @+id/content
   }
}
// where flag inflatingInProgress initially = true and is set to false after 
// finishing inflating the layout for ContentButton

Hope this helps. Good luck.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜