0

I have made a Custom ViewGroup. Detail about this Custom ViewGroup is found here from my earlier question. The problem I am facing here is , whenever I try to add buttons in the LinearLayout that is inside the custom Viewgroup, the buttons never get shown. I have tried many things but the button is never displayed, do I have to do something in the custom viewgroup, I even tried inflating the button but still did not work.

Code for Custom ViewGroup:

public class RootViewLayout extends ViewGroup  {
      private View mDrawView;
      private View mSlideView;
      private int mTop;
      private int mDragRange;

      public RootViewLayout(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
      @Override
      protected void onFinishInflate() {
          mDrawView  = findViewById(R.id.content_frame_white);
          mSlideView = findViewById(R.id.slide_frame);       
     }
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         int widthSize = MeasureSpec.getSize(widthMeasureSpec);
         int heightSize = MeasureSpec.getSize(heightMeasureSpec);
         setMeasuredDimension(widthSize, heightSize);   
     }
     @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom){
            bringChildToFront(mDrawView);
            mDrawView.layout(0, 0, right, bottom);
            mSlideView.layout(0, 0, right/2, bottom);   
     }
}

and the XML :

<com.example.drawapp.RootViewLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Root_View_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">
    <com.example.drawapp.DrawView
        android:id="@+id/content_frame_white"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/whitepaperwithcoffeestain">    
    </com.example.drawapp.DrawView>
    <LinearLayout 
        android:id="@+id/slide_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/slidebackgrd"
        android:orientation="vertical">
      <Button 
        android:id="@+id/pen"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:background="@drawable/pic"/>
    </LinearLayout>
</com.example.drawapp.RootViewLayout>
Community
  • 1
  • 1
solti
  • 4,339
  • 3
  • 31
  • 51
  • @Rod_Algonquin :- I have hyper linked the code. http://stackoverflow.com/questions/24168362/how-to-manage-to-bring-one-child-in-front-of-other-in-custom-viewgroup – solti Jun 14 '14 at 19:31

1 Answers1

1

sorry for the late comment.if you didn't solve it yet,apparently you have to do the same to your button what you did for your LinearLayout

View b= mSlideView.findViewById(R.id.pen);
b.layout(0, 0, right/4, bottom); 

checked it and it displayed the buttons width as half of the linearlayout and height as the bottom parameter

user1779374
  • 334
  • 1
  • 4
  • 15