我在移动应用程序中使用了一些scrolling
textViews
,但是最近我注意到text
启动scrolling
时会有一些滞后。为什么会这样?我有两个使用相同代码的不同fragments
,但是scrolling
textViews
不在另一个上“滞后”。我正在尝试找出问题所在,但找不到。欢迎任何帮助!
layout.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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/card_view_bg"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="@+id/cardArtImageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/cardDetailsImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--
<ImageView
android:id="@+id/cardDetailsImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/card_details_box" /> -->
<!-- Implement scrolling text
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
-->
<!-- passive skill desc
<TextView
android:id="@+id/passiveSkillDesc"
android:layout_width="395dp"
android:layout_height="33dp"
android:fontFamily="monospace"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="13sp"
android:textStyle="italic"
android:visibility="invisible"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="602dp" />
-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="225dp"
android:background="@drawable/card_details_closed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/HP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="37dp"
android:layout_weight="1"
android:text="0000"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="0000" />
<TextView
android:id="@+id/ATT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="78dp"
android:layout_toEndOf="@+id/HP"
android:layout_weight="1"
android:text="0000"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="0000" />
<TextView
android:id="@+id/DEF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="46dp"
android:layout_weight="1"
android:text="0000"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="0000" />
</RelativeLayout>
<TextView
android:id="@+id/leaderSkillDesc"
android:layout_width="250dp"
android:layout_height="15dp"
android:layout_above="@+id/superAttackTitle"
android:layout_alignParentEnd="true"
android:layout_marginBottom="14dp"
android:layout_marginEnd="35dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="@color/white"
android:textSize="13sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintVertical_bias="0.626" />
<TextView
android:id="@+id/superAttackTitle"
android:layout_width="250dp"
android:layout_height="15dp"
android:layout_above="@+id/superAttackDesc"
android:layout_alignStart="@+id/superAttackDesc"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="@android:color/holo_blue_light"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/superAttackDesc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/superAttackDesc"
android:layout_width="255dp"
android:layout_height="15dp"
android:layout_alignEnd="@+id/leaderSkillDesc"
android:layout_alignParentBottom="true"
android:layout_marginBottom="73dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="@android:color/white"
android:textSize="13sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</RelativeLayout>
<!-- passive skill title
<TextView
android:id="@+id/passiveSkillTitle"
android:layout_width="189dp"
android:layout_height="30dp"
android:fontFamily="monospace"
android:textAlignment="viewStart"
android:textColor="@color/cardDetailsTextColor"
android:textSize="12sp"
android:visibility="invisible"
tools:layout_editor_absoluteX="207dp"
tools:layout_editor_absoluteY="543dp" />
-->
</LinearLayout>
更新
当我将手机分辨率设为4K(s8)时,这种延迟实际上也发生在第二个片段中!
最佳答案
您可能有一个问题
android:layout_weight="1"
如here所述,设置权重对性能不利。
嵌套权重不利于性能,因为:
布局权重要求对小部件进行两次测量。当具有非零权重的LinearLayout嵌套在另一个内部时
权重非零的LinearLayout,然后是测量次数
呈指数增长
但是,此后事情发展了,谷歌引入了一种新的布局:
ConstraintLayout
。我强烈建议您改用它:ConstraintLayout