Android Studio ScrollView模糊内容

时间:2017-07-27 21:13:56

标签: android

我正在使用Android Studio 1.2.2,我遇到了无法解决的scrollView问题。 问题是,如果我向滚动视图添加一个按钮,那么当我滚动面板时,按钮会留下模糊的痕迹。 (就像在旧窗口中,当PC冻结时,在屏幕上移动窗口会导致在桌面上留下痕迹,因为桌面不会被重绘)

这是一个例子 The grey square buttons were added, and at the bottom you can see like there are more buttons under it, where as, in reality, there are not, it is just not redrawn background

添加了灰色方形按钮,在底部你可以看到它下面有更多按钮,实际上,没有,它只是没有重绘背景

通过编辑xml或以编程方式构建GUI来执行followind时会发生此问题

  1. 仅将一个或多个按钮直接添加到scrollview
  2. 将TableLayout添加到ScrollView,然后将TableRow添加到我添加按钮
  3. 将TableLayout添加到ScrollView,然后将TableRow添加到我添加Frame布局和该按钮
  4. 我使用的虚拟模拟器是 The emulator used to run code

    拜托,如果你们中的任何一个人知道问题在哪里,你能指出我正确的方向吗?下面我提供代码

    GameActivity.java中的代码

    public class GameActivity extends Activity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        //hide status bar
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        ActionBar actionBar = getActionBar();
        actionBar.hide();
    
    
        setContentView(R.layout.activity_game);
    
        //add components
        mImageView = (ImageView) findViewById(R.id.ID_HealthImageView);
        mImageView.setImageResource(R.drawable.test);
    
        //init table layout content
        createGui_FillTable((TableLayout) findViewById(R.id.ID_table_layout), 6, 3, 210);
    }
    private void createGui_FillTable(TableLayout tl, int rows, int cols, int size_of_button)
    {
        if(rows <= 0 || cols <= 0)
            return;
    
        for(int z = 0; z < rows; z++) {
            TableRow TR = new TableRow(this);
            TR.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    
            for (int i = 0; i < cols; i++)
                TR.addView(create_button_forTable(size_of_button));
    
            tl.addView(TR, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
        }
    }
    private Button create_button_forTable(int size_of_button)
    {
        //frame layout first
        /*FrameLayout FL = new FrameLayout(this);
        FL.setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));*/
    
        //button
        Button B = new Button(this);
        B.setText("");
        B.setLayoutParams(new TableRow.LayoutParams(size_of_button, size_of_button));
    
        //FL.addView(B);
        return B;
    }
    

    这里,关注的主要方法是以下调用

    createGui_FillTable((TableLayout) findViewById(R.id.ID_table_layout), 6, 3, 210);
    

    现在,Activity_game.xml包含此代码(完全剪切和粘贴)

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="janglaser.survival.GameActivity">
    
    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/ID_HealthImageView"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="48dp" />
    
    <ScrollView
        android:layout_width="300dp"
        android:layout_height="400dp"
        android:id="@+id/scrollView"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="50dp">
    
        <TableLayout
            android:id="@+id/ID_table_layout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignBottom="@+id/ID_HealthImageView"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal">
        </TableLayout>
    </ScrollView>
    

    感谢您的任何回复或建议,也感谢您的时间,如果您再来这里。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。问题是父容器和表格布局容器没有指定背景颜色,因此没有重绘。