добавить LinearLayout через addContentView ().Скользящий ящик теперь под последним добавленным Контентом - PullRequest
0 голосов
/ 29 февраля 2012

Друзья

У меня есть XML-файл, включая выдвижной ящик. Я устанавливаю ContentView в начале приложения.

Я динамически создаю LinearLayout в Java с несколькими TextViews и Edittext и добавляю его в приложение через addContentView (). SlidingDrawer все еще работает, но LinearLayout, который я добавил с помощью addContentView (), отображается над SlidingDrawer. Есть ли способ заставить работать 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);

Я рад любой поддержке и обходной путь !!!

вот мой 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>

Ответы [ 2 ]

2 голосов
/ 29 февраля 2012

Вам нужны незначительные изменения.

  • Дайте идентификатор своему родителю LinearLayout в формате XML (скажем, android:id="@+id/parent_container").
  • Вы получите LinearLayout в Java-файле.

примерно так:

LinearLayout container=(LinearLayout)this.findViewById(R.id.parent_container);
  • Теперь при добавлении новых View к container мы будем использовать индекс, чтобы поместить представление в конкретныйindex.

примерно так:

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

Мы вычли -2, потому что мы хотим поместить View во второй последний индекс.Так что SlidingDrawer по-прежнему на последнем индексе.

1 голос
/ 29 февраля 2012

Android рисует Представления в порядке добавления их в контейнер, поэтому ваше представление будет отображаться в Drawer.

Самым простым решением, вероятно, было бы добавление вашего привычного представления в FrameLayout (или любой другой макет), определенный в xml.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...