我创建了一个简单的 Android 活动,并为个人资料图片添加了一些卡片视图和图像视图。
图像位于滚动视图内。在某些设备上,滚动视图会自动滚动。我无法重现原因。在应用程序设置中清除缓存后,问题解决了。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/border_shadow">
<androidx.cardview.widget.CardView
android:id="@+id/profileIMG"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:elevation="10dp"
app:cardCornerRadius="25dp">
<ImageView
android:id="@+id/userProfileImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:scaleType="centerCrop"
/>
</androidx.cardview.widget.CardView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/backToMenu"
app:borderWidth="0dp"
android:backgroundTint="@color/primaryColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="end|bottom"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:tint="#fff"
android:contentDescription="Benutzer auswählen"
android:src="@drawable/ic_baseline_arrow_back_white_24" />
</RelativeLayout>
<Button
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:textSize="20sp"
android:padding="40dp"
android:layout_marginBottom="50dp"
android:background="@drawable/title"
android:elevation="20dp"
android:text="Wählen Sie das zu beobachtende Kind aus"
android:textColor="@color/white" />
<!-- android:layout_below="@id/title"-->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/title"
android:layout_marginBottom="50dp"
android:layout_weight="1">
<TableLayout
android:id="@+id/childTable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:stretchColumns="*">
<TableRow/>
</TableLayout>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_alignParentBottom="true"
app:labelVisibilityMode="labeled"
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="@drawable/tab_items"
app:itemTextColor="@drawable/tab_items"
app:menu="@menu/navigation_childselection" />
你有什么想法吗?
我确实在 XML 布局上发现了一些可能导致闪烁的冗余。
删除你的
,它通常不用于android:layout_weight="1
ScrollView
尝试具体修改您的
,因为它可能是罪魁祸首 背后闪烁的问题。更改您的ImageView
和layout_width
变成layout_height
或特定的东西。wrap_content
还可以尝试将
<ScrollView>
设置为 android:focusableInTouchMode="true">
以确保视图自动获得焦点,这可能会导致滚动。
您还可以尝试以编程方式禁用滚动并在需要时启用它。
scrollView.setEnabled(false);
如果都不起作用,可能是一些设备特定问题。