如何解决Android/Java:如何在导航栏中的 Fragment 中的 ScrollView 中使用 ConstraintLayout?
我在包含一个带有 ConstraintLayout 的 ScrollView 时遇到问题。我怎样才能将两者混合?我想很好地调整屏幕大小,但如果按钮数量增加,则可以滚动屏幕。
我试过了,但没有成功。我用过那个ticket
<ScrollView
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/homeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/imagealliance"
android:backgroundTint="#80FFFFFF"
android:backgroundTintMode="src_over"
android:gravity="center"
android:theme="@style/AppTheme"
tools:context=".LoginActivity">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:alpha="0.6"
android:scaleType="fitXY"
android:src="@drawable/logoalliance"
app:layout_constraintBottom_toTopOf="@+id/txt_login"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
这是按钮的代码:
public class HomeFragment extends Fragment {
...
layout.addView(eventBtn);
if (i == 0)
{
test1 = eventBtn.getId();
Log.d("test1",String.valueOf(eventBtn.getId()));
}
if (i == countUser.length() - 1)
{
test2 = eventBtn.getId();
Log.d("test2",String.valueOf(eventBtn.getId()));
}
这是布局的代码:
// Create ConstraintSet
ConstraintSet constraintSet = new ConstraintSet();
// Make sure all previous Constraints from ConstraintLayout are not lost
constraintSet.clone(layout2);
// Create Rule that states that the START of btn_contact_us1 will be positioned at the END of btn_contact_us2
constraintSet.connect(imageView1.getId(),ConstraintSet.START,test1,ConstraintSet.END);
constraintSet.applyTo(layout2);
提前致谢
解决方法
尝试通过以下代码更新您的 xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivityStack">
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:alpha="0.6"
android:scaleType="fitXY"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。