2012-02-29 1 views
0

友だち、addContentView()を使用してLinearLayoutを追加します。最後に追加された引き出しの下にスライドするコンテンツ

私はスライド式引き出しを含むxmlファイルを持っています。 アプリケーションの先頭に「コンテンツビュー」を設定しました。

いくつかのTextViewとEdittextを使ってJavaでLinearLayoutを動的に作成し、addContentView()を使用してアプリケーションに追加します。 SlidingDrawerは引き続き動作しますが、SlidingDrawerの上にaddContentView()によって追加されたLinearLayoutが表示されます。 SlidingDrawerを正しく動作させる方法はありますか?

相続人

私のコード

  setContentView(R.layout.real_time_report_layout); 
      LinearLayout linearLayoutRealTimeReportActivity = new LinearLayout(ctx); 


      TextView tv_questionType1 = new TextView(ctx); 

    linearLayoutRealTimeReportActivity.addView(tv_questionType1); 

      addContentView(linearLayoutRealTimeReportActivity, layoutParamsRealTimeReportActivity); 

の一部私は、任意のサポートのためにうれしいも回避!

HERESに私のxmlレイアウト

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <EditText 
     android:id="@+id/et_real_time_report_description" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <requestFocus /> 
    </EditText> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

     <Button 
      android:id="@+id/b_real_time_report_send" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:text="@string/b_real_time_report_send" > 
     </Button> 

     <Button 
      android:id="@+id/b_real_time_report_cancel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:text="@string/b_real_time_report_cancel" > 
     </Button> 
    </LinearLayout> 
</LinearLayout> 

<SlidingDrawer 
    android:id="@+id/sd_real_time_report_layout_SlidingDrawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:content="@+id/content" 
    android:handle="@+id/sd_real_time_report_layout_handle" > 

    <Button 
     android:id="@+id/sd_real_time_report_layout_handle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Handle" > 
    </Button> 

    <RelativeLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <com.google.android.maps.MapView 
      android:id="@+id/mv_real_time_report" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginBottom="50dp" 
      android:apiKey="0IfKjDM6XzpM6rGFR0H6X03Y1aWVBOnJ1C8b6wQ" 
      android:clickable="true" 
      android:enabled="true" /> 

     <TextView 
      android:id="@+id/tv_real_time_report_userLocation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="100dp" 
      android:text="test" 
      android:textSize="20dp" > 
     </TextView> 

     <Button 
      android:id="@+id/b_real_time_report_deleteUserLocationPin" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:text="@string/b_real_time_report_deleteUserLocationPin" /> 

     <ToggleButton 
      android:id="@+id/tb_real_time_report_chooseLocation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:textOff="@string/tb_real_time_report_ChooseLocationOFF" 
      android:textOn="@string/tb_real_time_report_ChooseLocationON" /> 
    </RelativeLayout> 
</SlidingDrawer> 

+1

あなたのXMLレイアウトも投稿してください。 –

答えて

2

少し変更する必要があります。

  • は(android:id="@+id/parent_container"、のは言わせて)レイアウトXMLで自分の親LinearLayoutにIDを与えます。
  • LinearLayoutはjavaファイルになります。

このような何か:

LinearLayout container=(LinearLayout)this.findViewById(R.id.parent_container); 
  • containerに新しいViewを追加するとき、我々は特定のインデックスでビューを置くためにインデックスを使用します。

このような何か:

container.addView(linearLayoutRealTimeReportActivity, container.getChildCount()-2); 

我々は引き算-2我々は最後から二番目のインデックスでビューを載せていきたいと思いますので。 したがって、SlidingDrawerはまだ最後のインデックスにあります。

+0

ありがとうございました!!!私はインデックスを必要としませんでした。 LinearLayoutにidとaddViewをLinearLayoutに与えてください。 – Arnold

+0

いいえ、あなたの 'LinearLayout'に' SlidingDrawer'があると考えていました。ハッピーコーディング.. –

+0

素晴らしい答え、ありがとう! – conor

1

のAndroidは、コンテナに追加するために、ビューを描画するので、あなたのビューには、引き出しの下に描画されます。

最も簡単な解決法はおそらく、xmlで定義されたFrameLayout(または他のレイアウト)にcusomビューを追加することです。

関連する問題