ScrollView SmoothScroll, не показывая последний элемент - PullRequest
0 голосов
/ 09 мая 2018

ОБНОВЛЕНИЕ Для XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="100">
    <!--App Bar Layout Pane-->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:background="@drawable/AppBarBackground"
        android:weightSum="100">

    <!--Unrelated XML Code-->

    </LinearLayout>
    <!--App Bar Layout Pane end-->
    <!--Body Pane-->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="93"
        android:weightSum="100"
        android:background="@drawable/AppBackground">
    <!--Left Pane-->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="37"
            android:background="@color/whiteWithAlpha75">

    <!--Unrelated XML Code-->

        </LinearLayout>
    <!--Left Pane end-->
    <!--Right Pane-->
        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="43">
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="100">
            <!--Right Pane Header-->
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="8"
                    android:weightSum="100"
                    android:background="@color/whiteWithAlpha10"
                    android:paddingLeft="15dp"
                    android:paddingRight="15dp">
                    <TextView
                        android:text="Item(s)"
                        android:fontFamily="@string/fontFamily"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="24"
                        android:textColor="@color/grayDark"
                        android:gravity="center|left"
                        android:textSize="@dimen/textSizeXSmall" />
                    <TextView
                        android:text="Unit Price"
                        android:fontFamily="@string/fontFamily"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="17"
                        android:textColor="@color/grayDark"
                        android:gravity="center"
                        android:textSize="@dimen/textSizeXSmall" />
                    <TextView
                        android:text="Quantity"
                        android:fontFamily="@string/fontFamily"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="28"
                        android:textColor="@color/grayDark"
                        android:gravity="center"
                        android:textSize="@dimen/textSizeXSmall" />
                    <TextView
                        android:text="Discount"
                        android:fontFamily="@string/fontFamily"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="16"
                        android:textColor="@color/grayDark"
                        android:gravity="center"
                        android:textSize="@dimen/textSizeXSmall" />
                    <TextView
                        android:text="Total"
                        android:fontFamily="@string/fontFamily"
                        android:gravity="center|right"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="15"
                        android:textColor="@color/grayDark"
                        android:textSize="@dimen/textSizeXSmall" />
                </LinearLayout>
            <!--Right Pane Header end-->
            <!--Right Pane Item Selected-->
                <android.support.v4.widget.NestedScrollView
                    android:id="@+id/scrollItemSelectedArea"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="92"
                    android:paddingBottom="5dp"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    android:background="@color/whiteWithAlpha15">
                    <LinearLayout
                        android:id="@+id/llItemSelectedArea"
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_margin="5dp" />
                </android.support.v4.widget.NestedScrollView>
            <!--Right Pane Item Selected end-->
            <!--Right Pane Functions-->
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="39"
                    android:weightSum="100">

    <!--Unrelated XML Code-->

                </LinearLayout>
            <!--Right Pane Functions end-->
            </LinearLayout>
        </FrameLayout>
    <!--Right Pane end-->
    </LinearLayout>
<!--Body Pane end-->
</LinearLayout>

Когда элементы в списке достигли конца высоты прокрутки, она должна выполнить прокрутку, чтобы показать последний выбранный элемент, я вызываю smoothScrollBy при каждом выборе элемента. Но когда у меня есть, например, 6 элементов, и мое прокручиваемое изображение может содержать только 5 элементов на экране, оно не прокручивается вверх для 6-го элемента. И когда я добавляю другой элемент, он показывает 6-й элемент, а 7-й элемент только что заменил 6-й элемент из скрытого. Моя высота прокрутки соответствует matched_parent и не имеет перекрывающегося макета внизу, поэтому нет места для последнего элемента, который нужно скрыть. Я не знаю, есть ли дополнительное пространство в виде прокрутки.

Как я могу исправить эту проблему?

Здесь я добавляю новый элемент

    public void renderItemSelected(ENT_TransactionItems entityTransactionItem, string displayName)
    {
        entityTransactionItemList.Add(entityTransactionItem);

        View vNewView = activity.LayoutInflater.Inflate(Resource.Layout.Layout_ItemSelected, llItemSelected, false);

        TextView tvItemName = vNewView.FindViewById<TextView>(Resource.Id.tvItemName);
        TextView tvItemAmount = vNewView.FindViewById<TextView>(Resource.Id.tvItemPrice);
        EditText etItemQuantity = vNewView.FindViewById<EditText>(Resource.Id.tvItemQuantity);
        Button btnDiscount = vNewView.FindViewById<Button>(Resource.Id.btnDiscount);
        TextView tvTotal = vNewView.FindViewById<TextView>(Resource.Id.tvTotal);

        //other code

        llItemSelected.AddView(vNewView);
        viewList.Add(vNewView);

        scrollItemSelectedArea.SmoothScrollBy(0, llItemSelected.Height);
    }

Это образец изображения

enter image description here

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