【问题标题】:Android Studio ScrollView blurred contentAndroid Studio ScrollView 内容模糊
【发布时间】:2017-08-02 05:43:40
【问题描述】:

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

这是一个插图

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

当通过编辑 xml 或以编程方式构建 GUI 进行后续操作时会发生此问题

  1. 直接向滚动视图添加一个或多个按钮
  2. 将 TableLayout 添加到 ScrollView,然后添加 TableRow,我添加按钮
  3. 将 TableLayout 添加到 ScrollView,然后添加 TableRow,然后添加 Frame 布局和该按钮

我使用的虚拟模拟器是

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

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>

感谢您的任何善意回应或建议,如果您红到这里,也感谢您的时间。

【问题讨论】:

    标签: android


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 2022-07-08
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多