首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >性能不好的林特警告- 80+视图

性能不好的林特警告- 80+视图
EN

Stack Overflow用户
提问于 2013-03-04 13:40:24
回答 3查看 4.1K关注 0票数 1

我收到了这个林特警告错误:highscores.xml has more than 80 views bad for performance。这是我的高分表,有15行3列。这是Lite版本的我的应用程序和我的付费版本将容纳30行。

我的问题是如何优化这段代码?一定有更好的办法。

highscores.xml

代码语言:javascript
复制
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativelayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="5dp"
    android:paddingBottom="65dp"
    android:background="@drawable/scroll" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textStyle="bold"
        android:textSize="18sp"
        android:paddingBottom="10dp"
        android:paddingTop="65dp" />

    <LinearLayout
        android:id="@+id/linearlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingTop="5dp" >

        <Button 
            android:id="@+id/homeBtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="14sp" />

        <Button 
            android:id="@+id/clearHS"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="14sp" />
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:background="@drawable/scrollviewborder"
        android:layout_below="@id/title"
        android:layout_above="@id/linearlayout"
        android:fillViewport="true"
        android:scrollbars="none" >

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r1s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r1c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r1b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r2s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r2c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r2b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r3s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r3c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r3b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r4s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r4c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r4b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r5s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r5c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r5b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r6s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r6c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r6b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r7s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r7c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r7b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r8s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r8c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r8b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r9s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r9c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r9b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r10s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r10c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r10b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r11s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r11c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r11b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r12s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r12c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r12b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r13s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r13c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r13b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r14s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r14c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r14b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>

            <View 
                android:layout_width="fill_parent"
                android:layout_height="1dp"       
                android:background="#C2BEBF" />

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TextView
                    android:id="@+id/r15s"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="25"
                    android:gravity="center"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/r15c"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="75"
                    android:gravity="center"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/r15b"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:textSize="14sp" />
            </TableRow>
        </TableLayout>
    </ScrollView>
</RelativeLayout>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-04 13:42:07

使用ListView而不是ScrollView中的TableLayout。这不仅使您能够根据可用的屏幕大小,拥有尽可能多的行,而且您还可以删除按钮,根据单击列表项来执行按钮应该做的任何事情。

票数 7
EN

Stack Overflow用户

发布于 2013-03-04 13:47:15

如果您只想创建一个TableLayout,那么您可以通过编程方式添加TableRow,而不是在layout.xml中创建所有内容(这将避免Lint警告&您可以根据自己的意愿修改表行)。这里有一个关于你如何做到这一点的片段。

代码语言:javascript
复制
TableLayout table = new TableLayout(this);

FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT);
table.setLayoutParams(lp);
table.setStretchAllColumns(true);

TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT,
        1.0f);
TableRow.LayoutParams cellLp = new TableRow.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT,
        1.0f);
for (int r = 0; r < 2; ++r)
{
    TableRow row = new TableRow(this);
    for (int c = 0; c < 2; ++c)
    {
        Button btn = new Button(this);
        btn.setText("A");
        row.addView(btn, cellLp);
    }
    table.addView(row, rowLp);
}
setContentView(table);
票数 1
EN

Stack Overflow用户

发布于 2019-03-16 10:20:29

有一些方法可以避免这种情况:

1.使用RecyclerView

如果您的设计有许多彼此相似的UI组件,那么您应该使用RecyclerView,这在本例中是最好的方法,并在需要时处理视图的回收。

2.使用复合可绘图

如果UI的图像接近TextViewEditTextButton,则可以使用drawable属性将图像添加到TextViewButtonEditText的左侧、右侧、顶部、底部。您只需要使用复合绘图,不需要使用LinearLayoutImageView

如果要在左侧添加图像,则可以使用以下可绘制的左侧:

代码语言:javascript
复制
android:drawableLeft="@drawable/image"

这将向TextViewButtonEditText的左侧添加一个图像,这取决于您使用该属性的位置。

3.使用约束布局

这个强大的布局确实帮助您在这个单一布局中设计复杂的UI,从而帮助您消除布局的嵌套。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15202900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档