android - ScrollView SmoothScrollBy 不显示最后一项
问题描述
更新 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);
}
这是示例图像
解决方案
推荐阅读
- amazon-web-services - AWS CLI CodeArtifact :为 list-package-versions 子命令的 --package 标志提供什么值
- java - 在我的课本上得到了这个问题,无法理解程序中的逻辑或答案键中给出的答案(Java)
- spring - 如何在 Kotlin 中排除多个 Spring 配置文件?
- snowflake-cloud-data-platform - 如何使用 .Net 库管理对 Snowflake 的长时间运行过程调用
- reactjs - 打字稿错误:不可分配给类型“IntrinsicAttributes”。“IntrinsicAttributes”类型上不存在属性“子项”
- flutter - 不能在命名参数 $data 之后使用位置参数以在颤振中添加 cpomment
- azure - 需要后端初始化,请运行“terraform init”
- c# - 并行处理任务
- plugins - 安装moodle插件失败
- android - 如何将心率数据从智能手环传输到 Android 应用程序