Tuesday, 3 September 2013

Adding a View to a child of a custom View

Adding a View to a child of a custom View

I have created a custom view called SlideUpDownLayout that extends
RelativeLayout. It contains an ImageButton and a HorizontalScrollView.
Inside HorizontalScrollView there is a LinearLayout. I would like whatever
View I add via xml to the SlideUpDownLayout to be added automatically to
the LinearLayout. I tried by overriding onFinishInflate() but it seems
that when I use this the ImageButton does not respond.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/transparent"
tools:context=".SlideUpActivity"
android:id="@+id/slideLayout">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@null"
android:src="@drawable/arrow_down" />
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_alignParentBottom="true"
android:layout_below="@+id/imageButton1" >
<LinearLayout
android:id="@+id/magic_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- I would like the views to get inside here -->
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
<!--for example -->
<com.example.downbar.SlideUpDownLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/checkBox2" >
<!-- these ImageViews here to be added in the LinearLayout
magic_layout-->
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/exp_icon" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</com.example.downbar.SlideUpDownLayout>

No comments:

Post a Comment