[컴][안드로이드] ViewStub 사용법


ViewStub 사용법


MainActivity.java

 // show the explanation view
 View v1 = v.get(0);
 ViewStub stub = (ViewStub)v1.findViewById(R.id.stub_howto);
 stub.setVisibility(View.VISIBLE);
 RelativeLayout rlayout = (RelativeLayout)v1.findViewById(R.id.howto_import);
 ImageView iview = (ImageView)rlayout.findViewById(R.id.imageView1);


stub.inflate()
stub.setVisibility(View.VISIBLE);
RelativeLayout rlayout = (RelativeLayout)v1.findViewById(R.id.howto_import);
대신에
RelativeLayout rlayout = (RelativeLayout)stub.inflate();
를 사용할 수 있다.


listactivity.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- layout for listview -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 
 <!--
  NOTICE
  
  At SlidingView class, It uses the .getChildAt(0) method
  to obtain the ListView at the below. Therefore if you want
  to add a view here, the code in SlidingView should be modified.
   
  -->

 <ListView
     android:id="@+id/listview"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:divider="@color/divider_color"
     android:drawSelectorOnTop="false">
      
 </ListView>
 
 <!--
  progressbar 
  -->
 <ProgressBar
     android:id="@+id/progressbar"
     style="@android:style/Widget.ProgressBar.Small"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>
 
 <ViewStub
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/stub_howto"
     android:inflatedId="@+id/howto_import"
     android:layout="@layout/viewstub_howto"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     
     android:layout_gravity="top" />

</FrameLayout>

viewstub_hotwo.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
 <ImageView
     xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/imageView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentRight="true"
  android:src="@drawable/howto_arrow"
  android:contentDescription="imagetest"
  >
       
 </ImageView>
</RelativeLayout>
 

댓글 없음:

댓글 쓰기