【发布时间】:2021-09-09 12:34:27
【问题描述】:
我以编程方式创建了一个滚动视图
从 .xml 文件中提取
<!-- Spinner -->
<RelativeLayout
android:id="@+id/myScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
app:layout_constraintTop_toBottomOf="parent"
android:layout_marginTop="125dp"
tools:context=".QuizActivity">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal">
<LinearLayout
android:id="@+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:background="@color/white"
android:layout_marginTop="20dp"
android:layout_marginBottom="15dp"/>
</HorizontalScrollView>
</RelativeLayout>
这里是.kt代码sn-p
/***************** SCROllL VIEW *****************/
fun showSpinner(show: Boolean) {
if (linearLayout == null) {
linearLayout = findViewById(R.id.linear1)
if (show) {
val layoutInflater = LayoutInflater.from(this)
...
...
} else {
// Close de scrollView
// TODO: fermer le spinner
if (linearLayout!! != null) {
linearLayout!!.visibility = View.GONE
}
// TODO: Add a frame auround the scroll view to get a better look
}
}
}
但是现在当我需要再次使用 showSpinner(true) 重新创建它时,它会重新创建但它不会显示在屏幕上!
我在调试器中看到程序已创建,但屏幕上没有任何内容?
任何帮助将不胜感激。 安卓
【问题讨论】:
标签: kotlin layout scrollview