【发布时间】:2021-09-10 20:17:08
【问题描述】:
我正在开发我的第一个大型 android 项目,但我遇到了一个问题。 我必须显示一个带有条款和条件文本的弹出窗口。由于它的大小,文本必须滚动。我的具体问题是,出于视觉原因,我希望顶部位于屏幕下方,而我所做的任何事情都不会让它从最顶部移动。
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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/tc_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_long"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A very long string of text"></TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
我已经尝试添加:
tools:layout_editor_absoluteY="100dp" />
和
android:layout_marginTop="100dip"
在各个地方 - 滚动视图本身、父 LinearLayout 等,但没有任何作用。
我已经查看了显示窗口的代码,并尝试在 ScrollView 类中使用 scrollTo 方法,如下所示:
View tcView = inflater.inflate(R.layout.t_and_c_dialog, null);
ScrollView tcScroll = (ScrollView) tcView.findViewById(R.id.tc_scroll);
tcScroll.scrollTo(0, 200);
PopupWindow pwTC = new PopupWindow(tcView, width, width, true);
pwTC.showAtLocation(new LinearLayout(this), Gravity.CENTER, 0, 0);
仍然没有喜悦。有人有什么想法吗? 非常感谢 托尼·雷诺兹
【问题讨论】:
标签: android scrollview