Android: просмотр и скрытие включенных макетов в относительном макете - PullRequest
0 голосов
/ 27 марта 2012

У меня есть две раскладки, одна из которых является основной раскладкой, внутри которой я включаю свою собственную раскладку клавиатуры.Когда я скрываю включенную раскладку, основная раскладка искажается.

Моя основная раскладка xml выглядит следующим образом.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_rl"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_header" >

<LinearLayout
    android:id="@+id/linHeader"
    style="@style/linHeader"
    android:layout_height="55dp"
    android:baselineAligned="false"
    android:weightSum="1" >

    <LinearLayout
        android:id="@+id/linLogo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".60"
        android:gravity="center_vertical" >

        <TextView
            android:id="@+id/tvOutletName"
            style="@style/linHeader_text"
            android:text="" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".40"
        android:gravity="right|center_vertical" >

        <LinearLayout
            android:id="@+id/btnAdvList"
            style="@style/btnChart"
            android:onClick="btnAdvList" >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/btnDownArrow"
            style="@style/btnDownArrow"
            android:onClick="btnCollapseExpand" >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/btnRightArrow"
            style="@style/btnRightArrow"
            android:onClick="btnDone" >
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/linSearch"
    style="@style/linSearch"
    android:layout_below="@+id/linHeader" >

    <EditText
        android:id="@+id/etSearchText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_weight="1"
        android:hint="@string/LblText_Search" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linInfo"
    style="@style/linInfo"
    android:layout_below="@+id/linSearch" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </Spinner>

    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </Spinner>

    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </Spinner>
</LinearLayout>

<LinearLayout
    android:id="@+id/linTitle"
    style="@style/lstTitle"
    android:layout_below="@+id/linInfo" >

    <TextView
        android:id="@+id/tvItems"
        style="@style/lstTitleText"
        android:layout_width="0dp"
        android:layout_weight="2"
        android:text="@string/LblText_Items" >
    </TextView>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/lsttitle_seperator" >
    </ImageView>

    <TextView
        android:id="@+id/tvOrder"
        style="@style/lstTitleText"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:text="@string/AdvList_Order" >
    </TextView>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/lsttitle_seperator" >
    </ImageView>

    <TextView
        android:id="@+id/tvTotal"
        style="@style/lstTitleText_Right"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:text="@string/AdvList_Total" >
    </TextView>
</LinearLayout>

<LinearLayout
    android:id="@+id/linBody"
    style="@style/linBody"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linKeypad"
    android:layout_below="@+id/linTitle"
    android:orientation="vertical"
    android:weightSum="1" >

    <ExpandableListView
        android:id="@+id/expandableList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:childDivider="#fff"
        android:focusable="true"
        android:groupIndicator="@android:color/transparent" >
    </ExpandableListView>
</LinearLayout>

<LinearLayout
    android:id="@+id/linKeypad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/linFooter" >

    <include
        android:id="@+id/linearLayoutKeyPad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/custom_decimal_keypad" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linFooter"
    style="@style/linFooter" >

    <TextView
        android:id="@+id/tvOrdersTaken"
        style="@style/linFooter_text"
        android:layout_weight="1" >
    </TextView>

    <TextView
        android:id="@+id/tvTotalValue"
        style="@style/linFooter_text"
        android:layout_weight="1"
        android:gravity="right" >
    </TextView>
</LinearLayout>

</RelativeLayout>

и включенная раскладка клавиатуры выглядит следующим образом

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayoutKeyPad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#efefef"
android:orientation="vertical"
>

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="#999"
        android:gravity="center_horizontal" >

        <Button
            android:id="@+id/btnKeyPad0"
            android:layout_width="40dip"
            android:onClick="btnKeyPad0"
            android:text="0" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad1"
            android:layout_width="40dip"
            android:onClick="btnKeyPad1"
            android:text="1" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad2"
            android:layout_width="40dip"
            android:onClick="btnKeyPad2"
            android:text="2" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad3"
            android:layout_width="40dip"
            android:onClick="btnKeyPad3"
            android:text="3" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad4"
            android:layout_width="40dip"
            android:onClick="btnKeyPad4"
            android:text="4" >
        </Button>

        <ImageButton
            android:id="@+id/btnKeyPadBackSpace"
            android:layout_width="40dip"
            android:onClick="btnKeyPadBackSpace"
            android:src="@drawable/backspace" >
        </ImageButton>
    </TableRow>
</TableLayout>

<TableLayout
    android:id="@+id/tableLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" >

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="#999"
        android:gravity="center_horizontal" >

        <Button
            android:id="@+id/btnKeyPad5"
            android:layout_width="40dip"
            android:onClick="btnKeyPad5"
            android:text="5" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad6"
            android:layout_width="40dip"
            android:onClick="btnKeyPad6"
            android:text="6" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad7"
            android:layout_width="40dip"
            android:onClick="btnKeyPad7"
            android:text="7" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad8"
            android:layout_width="40dip"
            android:onClick="btnKeyPad8"
            android:text="8" >
        </Button>

        <Button
            android:id="@+id/btnKeyPad9"
            android:layout_width="40dip"
            android:onClick="btnKeyPad9"
            android:text="9" >
        </Button>

        <Button
            android:id="@+id/btnKeyPadDecimal"
            android:layout_width="40dip"
            android:onClick="btnKeyPadDecimal"
            android:text="." >
        </Button>


        <Button
            android:id="@+id/btnKeyPadOk"
            android:layout_width="43dip"
            android:onClick="btnKeyPadOk"
            android:text="@string/LblText_Ok" >
        </Button>
    </TableRow>
</TableLayout>

</LinearLayout>

Расширяемый макет строки списка просмотра:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linOrderTakingList"
style="@style/lstRow" >

<TextView
    android:id="@+id/tvItemDesc"
    style="@style/lstRowText"
    android:layout_width="0dp"
    android:layout_weight="2" >
</TextView>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/lsttitle_seperator" >
</ImageView>

<TextView
    android:id="@+id/tvOrderQty"
    style="@style/lstRowText"
    android:layout_width="0dp"
    android:layout_weight="1" >
</TextView>

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/lsttitle_seperator" >
</ImageView>

<TextView
    android:id="@+id/tvOrderValue"
    style="@style/lstRowText_Right"
    android:layout_width="0dp"
    android:layout_weight="1" >
</TextView>

</LinearLayout>

Расширяемый дочерний макет списка:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
style="@style/lstRow_Expanded_1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/btnUnit"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="@string/LblText_Unit" >
    </Button>

    <Button
        android:id="@+id/btnCopy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="@string/MenuBtnText_Copy" >
    </Button>

    <TextView
        android:id="@+id/tvQty"
        style="@style/txtLable"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="right"
        android:text="@string/AdvList_Qty" >
    </TextView>

    <TextView
        android:id="@+id/tvQtyValue"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2" >

        <requestFocus />
    </TextView>
</TableRow>

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tvAvg"
        style="@style/txtLable"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/LblText_Avg" >
    </TextView>

    <TextView
        android:id="@+id/tvLag"
        style="@style/txtLable"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/LblText_Lag" >
    </TextView>

    <TextView
        android:id="@+id/tvUnitPr"
        style="@style/txtLable"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/LblText_Unit_Pr" >
    </TextView>

    <TextView
        android:id="@+id/tvMrp"
        style="@style/txtLable"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/LblText_MRP" >
    </TextView>

    <TextView
        android:id="@+id/tvSo"
        style="@style/txtLable"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/LblText_SO" >
    </TextView>
</TableRow>

<TableRow
    android:id="@+id/tableRow3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tvAvgValue"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/tvLagValue"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/tvUnitPrValue"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/tvMrpValue"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/tvSoValue"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />
</TableRow>

</TableLayout>

Снимок экрана макета перед просмотром клавиатуры:

image 1

и снимок экрана искаженного макета после отображения клавиатуры:

image 2

Я также пытался обновить дочерний вид, сделать вид недействительным, программно изменить относительное расположение.Пожалуйста, помогите мне с некоторыми решениями.Если я не помещу список выше клавиатуры, он не искажается, но представление списка скрывается за клавиатурой, что бесполезно.Мне в основном нужна клавиатура, чтобы выдвигать представление списка вверх, когда оно становится видимым, и возвращаться к нормальному состоянию, когда оно исчезает.

1 Ответ

1 голос
/ 28 марта 2012

Поскольку искажение происходит в расширенном представлении, проблема, вероятно, заключается в его макете.

Я бы посоветовал вам избавиться от TableLayout в вашем дочернем макете: иногда это непредсказуемо и приводит к тому же результату.может быть достигнуто без него (например, с использованием вложенных LinearLayout).

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