문제

I recently stumbled upon the sliding drawer in Android, after creating my first project which implements the same I have a few issues. I am using a list view inside of the sliding drawer and for that I need to implement onClickListener and extend Activity, now everything is working fine, albeit the sliding drawer opens and occupies almost all of the space in the view, I want it to open only half screen. I went through various posts on internet which ask me to extend SlidingDrawer and use method onMeasure which is not feasible for me (Or is it?). Secondly I would want to place the handle button on the top not centre. Below is my code:

activity_main.xml~~~>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="top"
>



<TextView
    android:text=""
    android:gravity="center|center_vertical"
    android:textColor="#000000"
    android:textSize="20dp"
    android:textStyle="bold"
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</TextView>

<SlidingDrawer
    android:layout_width="wrap_content"
    android:id="@+id/SlidingDrawer"
    android:handle="@+id/slideButton"

    android:content="@+id/contentLayout"

    android:animateOnClick="true"
    android:layout_height="match_parent"

    android:orientation="horizontal">

        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/slideButton"

            >
        </Button>
        <LinearLayout
            android:layout_width="wrap_content"
            android:id="@+id/contentLayout"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="10dip"
            android:background="#0080FF"
            android:layout_height="wrap_content">
            <ListView
                android:id="@android:id/list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
        </ListView>
    </LinearLayout>
</SlidingDrawer>
   </RelativeLayout> 




    .java file~~~~>

      public class slidingDrawerDemo extends ListActivity implements OnClickListener {


private ArrayAdapter<String> listAdapter ;  
Button slideButton,b1, b2,b3,b4;
SlidingDrawer slidingDrawer;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);






    setContentView(R.layout.activity_main);
    slideButton = (Button) findViewById(R.id.slideButton);
    slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);




    ListView LV = getListView();  //(ListView)findViewById(R.id.list);
    String []Test ={"Residential","Commercial","Customised Projects","SEZ","Brochure"};
    ArrayList<String> Plist = new ArrayList<String>(); 
    Plist.addAll(Arrays.asList(Test));
    listAdapter = new ArrayAdapter<String>(this, R.layout.list_dem, Plist);
    LV.setAdapter( listAdapter );



    LV.setOnItemClickListener(new OnItemClickListener() {
       public void onItemClick(AdapterView LV, View view,int position, long id) {


          Toast.makeText(slidingDrawerDemo.this,""+position, Toast.LENGTH_SHORT).show();

          if(position==0){
              initOne();
          }else if (position==1){
              initTwo();
          }else if (position==2){
              initThree();
          }else if (position==3){
              initFour();
          }else if (position==4){
              initFive();
          }



       }
       });




    slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
        @Override
        public void onDrawerOpened() {
          //  slideButton.setBackgroundResource(R.drawable.closearrow);
        }
    });

    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
        @Override
        public void onDrawerClosed() {
          //  slideButton.setBackgroundResource(R.drawable.openarrow);
        }
    });
}


    My list_dem.xml file~~~> 

     <TextView xmlns:android="http://schemas.android.com/apk/res/android"  
      android:id="@+id/rowTextView"   
      android:layout_width="wrap_content"   
      android:layout_height="wrap_content"  
      android:padding="10dp"  
      android:textSize="16sp" >  
    </TextView>  
도움이 되었습니까?

해결책

I found the answer: in my Slider defination in xml:

    android:topOffset="100.5dp"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top