2016-08-01 12 views
1

いくつかのポイントにするとスケール値の増加、私はのTextViewとスケール

TextView.animate().setDuration(0).scaleX(scale).scaleY(scale).start(); 

このコードを使用し、それがTextViewのを消します。私はなぜ知りません、そしてそれを防ぐ方法は?

[編集]私のテストコード

を取り付け[test_text_scale.xml]それは、この5月TestTextScale.java

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clipChildren="false" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/tv_test_scale" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:text="Test" /> 

    <Button 
     android:id="@+id/bt_up" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toEndOf="@+id/bt_down" 
     android:layout_toRightOf="@+id/bt_down" 
     android:text="Up" /> 

    <Button 
     android:id="@+id/bt_down" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:text="Down" /> 

</RelativeLayout> 

[TestTextScale.java]

import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 


public class TestTextScale extends AppCompatActivity { 

    // View 
    private TextView mTvTestZoom; 
    private Button mBtUp, mBtDown; 

    // Model 
    private int mCurrentScale = 1; 

    // OnClick listener 
    private View.OnClickListener mOnClickListener = new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      switch (v.getId()) { 

       case R.id.bt_up : { 
        upScale(); 
        setText(); 
       } break; 

       case R.id.bt_down : { 
        downScale(); 
        setText(); 
       } break; 
      } 
     } 
    }; 

    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.test_text_scale); 

     initView(); 
     initEvent(); 
    } 

    private void initView() { 

     mTvTestZoom = (TextView) findViewById(R.id.tv_test_scale); 
     mBtUp = (Button) findViewById(R.id.bt_up); 
     mBtDown = (Button) findViewById(R.id.bt_down); 

    } 

    private void initEvent() { 
     mBtDown.setOnClickListener(mOnClickListener); 
     mBtUp.setOnClickListener(mOnClickListener); 
    } 

    private void upScale() { 
     mCurrentScale += 1; 
     mTvTestZoom.animate().setDuration(0).scaleX(mCurrentScale).scaleY(mCurrentScale).start(); 
    } 

    private void downScale() { 
     mCurrentScale -= 1; 
     mTvTestZoom.animate().setDuration(0).scaleX(mCurrentScale).scaleY(mCurrentScale).start(); 
    } 

    private void setText() { 
     mTvTestZoom.setText(mCurrentScale + ""); 
    } 
} 
+1

コンテナのレイアウト境界を超えています。おそらく。 – Shaishav

答えて

1

のレイアウトxmlファイルでありますテキストビューがその親のレイアウト境界を超えているために起こります。これを克服するには、テキストビューの直接の親のxml記述にandroid:clipChildren="false"を単純に入れます。また、両親のためにそれを行う必要があります。

EDIT: コードを自分自身をテストする際に、私はTextViewには、次のログメッセージで消えなかったことが判明:

E/OpenGLRenderer: Font size too large to fit in cache. width, height = 635, 1028 

これは、Androidのハードウェアアクセラレーションモジュールで可能な問題によるものです。これを回避する方法の一つは、次のとおりです。

mTvTestZoom.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

これがうまく機能し、TextViewには一定の大きさの後に消えませんが、それは特定のTextViewのためのハードウェアアクセラレーションを無効にするので、それはアンチエイリアスを失う可能性があります。

+0

私はあなたの提案を試みましたが、うまくいきません上記のテストコードを添付しました、ありがとうございます(T- T) –

+0

@toptapsさて、見てみましょう。 – Shaishav

関連する問題