Android 从基本适配器滚动到listview的底部
我有一个Android 从基本适配器滚动到listview的底部,android,listview,Android,Listview,我有一个列表视图,在它里面有一个图像按钮。当用户单击该ImageButton时,一个新项目会膨胀,但每次我添加一个新项目时,我都必须向下滚动以查看添加的项目。我需要帮助,使滚动移动到最后一个项目后,它已被添加自动 请注意,我的ImageButton位于不同的布局中(但它是listview的一部分),同一布局具有LinearLayout,它充当我的子视图的父视图 这是我的xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLa
列表视图
,在它里面有一个图像按钮
。当用户单击该ImageButton时,一个新项目会膨胀,但每次我添加一个新项目时,我都必须向下滚动以查看添加的项目。我需要帮助,使滚动移动到最后一个项目后,它已被添加自动
请注意,我的ImageButton
位于不同的布局中(但它是listview的一部分),同一布局具有LinearLayout
,它充当我的子视图的父视图
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayoutOther"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/_5sdp">
<TextView
android:id="@+id/objectiveOtherCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Other Objectives"
android:layout_marginStart="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
android:textColor="@color/common_google_signin_btn_text_light_focused"
android:textSize="@dimen/_12ssp" />
<ImageButton
android:id="@+id/addOtherObjectiveTextBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/objectiveOtherCheckBox"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
android:background="@drawable/round_button2"
android:src="@android:drawable/ic_input_add"/>
//parent layout
<LinearLayout
android:id="@+id/otherObjLinearLayout"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_below="@+id/objectiveOtherCheckBox"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</RelativeLayout>
通知列表更改后,您需要调用scroll on
ListView
list_View.smoothScrollToPosition(list_View.getChildCount());
或如果从非Ui线程调用
list_View.post(new Runnable() {
@Override
public void run() {
list_View.smoothScrollToPosition(list_View.getChildCount());
}
});
如何从我的基本适配器访问ListView?这只是一种方法。在活动中创建一个公共方法并调用它。我将listview传递给我的基本适配器中的构造函数,然后我使用了你的代码,但它不起作用。有什么建议吗?
list_View.post(new Runnable() {
@Override
public void run() {
list_View.smoothScrollToPosition(list_View.getChildCount());
}
});