Android ScrollView没有';伸展不够
我在Android ScrollView没有';伸展不够,android,kotlin,android-scrollview,Android,Kotlin,Android Scrollview,我在ScrollView中有一个linerlayout(水平)。我试图通过编程方式在线性布局中添加文本视图和按钮 我的代码没有错误,但有一点小故障。MyScrollView仅适用于TextView而不适用于按钮的拉伸。抱歉解释不充分,也许截图有帮助: ❒ Eve gir.是一个按钮其余的是文本视图 我怎样才能使滚动视图也能拉伸和包裹我的按钮。我尝试设置fillViewPort,但没有成功 TextView添加代码: 布局的XML代码 您应该使用LinearLayout.LayoutParams.
ScrollView中有一个linerlayout(水平)
。我试图通过编程方式在线性布局中添加文本视图
和按钮
我的代码没有错误,但有一点小故障。MyScrollView
仅适用于TextView
而不适用于按钮的拉伸。抱歉解释不充分,也许截图有帮助:
❒ Eve gir.
是一个按钮
其余的是文本视图
我怎样才能使滚动视图
也能拉伸和包裹我的按钮
。我尝试设置fillViewPort
,但没有成功
TextView
添加代码:
布局的XML代码
您应该使用LinearLayout.LayoutParams.WRAP\u CONTENT
而不是ViewGroup.LayoutParams.MATCH\u PARENT
。试试这个代码
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT)
问题不是ScrollView
,而是LinearLayout
。当我删除“LinearLayout”的android:layout\u margin时,问题解决了。我仍然不知道为什么,但这个解决方案对我有效。对不起,我的问题仍然存在。您确定要调用createButton方法吗?是的,我正在设置onClick()方法,它工作正常。只是视觉问题。您是否尝试删除此应用程序:layout\u constraintHeight\u default=“wrap”?它覆盖了整个页面。看起来有点糟糕
private fun createButton(prTx: String, clk: Int) {
val button = Button(this)
button.text = prTx
button.setBackgroundColor(Color.TRANSPARENT)
button.gravity = Gravity.CENTER_HORIZONTAL;
button.textSize = 18F
button.transformationMethod = null;
button.setTextColor(Color.WHITE)
button.setShadowLayer(10F,5F,5F, Color.BLACK)
button.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
button.setOnClickListener {
when (clk) {
}
}
button.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)
val layout = findViewById<LinearLayout>(R.id.llText)
layout.addView(button)
}
<ScrollView
android:id="@+id/sv"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="#5B34515E"
android:fadeScrollbars="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/ivMutfak"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/clMiddle"
app:layout_constraintTop_toBottomOf="@+id/clMiddle"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:id="@+id/llText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical" />
</ScrollView>
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT)