Android Form with EditText makes the screen flash

2019-07-19 11:39发布

问题:

I don't know why my "Forms" activity are flashing when an EditText are focused and then a layout is scrolled. It just happen in devices with Android 4.0 + I am using a Table Layout and adding TableRow dynamically.

My TableRow is like that:

 <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/borda"
    android:layout_margin="10dip"
    android:paddingLeft="10dip"
    >
  <LinearLayout
    android:id="@+id/l1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="15dip"
    android:layout_marginBottom="15dip"
    >

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nome"
        android:textStyle="bold"
        android:textColor="#526691"
        android:textSize="15sp"
        android:paddingLeft="10dip"
        android:paddingRight="5dip"
         />


       <EditText
        android:id="@+id/valorLabel"
        android:layout_width="140dip"
        android:layout_height="wrap_content"
        android:textSize="15sp" 
        android:background="#ffffffff"   
        android:singleLine="true"   
        android:inputType="textCapSentences" 
         android:textColor="#777777" />          


 </LinearLayout>

</TableRow>

Then,I add the TableRow into a TableLayout....

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:cacheColorHint="#00000000"    
android:background="#dddddd">
<TextView
        android:id="@+id/add_instancia_tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/add_fornecedor_informacoes"
        android:textColor="#4c566c"
        android:textStyle="bold"
        android:paddingLeft="20dip"
        android:paddingTop="20dip"
        android:textSize="20dip"/>
<TableLayout 
android:layout_width="fill_parent"
android:id="@+id/table_novo_registro1"
android:layout_height="wrap_content"    
android:orientation="vertical"
android:background="#dddddd" >
...

Then,in the code, i inflate my TableRow

TableRow colunaNome= (TableRow) getLayoutInflater().inflate(R.layout.tablerownovocampo, null);
            LinearLayout linearlNome= (LinearLayout)colunaNome.getChildAt(0);   
            TextView textvNome=(TextView)linearlNome.getChildAt(0);
            textvNome.setText(R.string.nome);
            etNome=(EditText)linearlNome.getChildAt(1);

And a lot of TableRow are added.

The Question is...

Why are my Form flashing( blinking) when I scroll it? And Why does it happen only in Android 4.0 +?

I already saw this post .... http://android-developers.blogspot.com.br/2009/01/why-is-my-list-black-android.html but I am not working with ListView.

I'v already tried

android:cacheColorHint="#00000000"

in the TableLayout but, it didn't work.

回答1:

This will 100% work .....

ScrollView sv=(ScrollView) findViewById(R.id.scrollView1);

    sv.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            edttext.clearFocus();   
            return false;
        }
    });