10

アプリケーション内で以下を複製しようとしています。

ここに画像の説明を入力してください

ご覧のとおり、基本的には、その中に含まれるテキストビューの値を増減するボタンです。このボタンには、3つの視覚的状態があります->押されていない、減少、増加(上の画像に見られるように、ユーザーは増加矢印をタップすると、ボタンはその側で押されているように見えます)

現在の私の3つのボタンの状態は次のとおりです。

ここに画像の説明を入力してください ここに画像の説明を入力してください ここに画像の説明を入力してください

ご覧のとおり、私が抱えている問題は、テキストビューを正しくスキュー/回転できるため、視覚的に正しく見え、ボタンを増減したときにボタンと一緒に斜めに見えることです。

私はこれまでに2つの異なるアプローチを試しました。

  • onDraw()メソッドをオーバーライドしてキャンバスを歪めるカスタムテキストビュークラスを作成します。

    @Override
    public void onDraw(Canvas canvas) { 
       canvas.save(); 
    
       canvas.skew(0.2f, 0f);
    
       super.onDraw(canvas); 
       canvas.restore();
    }
    
  • Rotate3dAnimationクラスを統合し(ソースはこちら)、さまざまなバリエーションを使用して、次のような目的の結果を取得します。

       Rotate3dAnimation skew = new Rotate3dAnimation(
              30, 0, centerX, centerY, 0, false);
       txtAmount.startAnimation(skew); 
    

残念ながら、上の最初の画像を反映した正確な結果は得られていません。Z軸、スキュー、回転などで値を設定するのに混乱しています。

このようなことを経験したことがある人の助けをいただければ幸いです。前もって感謝します

4

2 に答える 2

8

さて、私も試してみましたが、次のようなものを思いつきました:

 public class DemoActivity extends TextView {
    Context context;
    String firstText = "$120.00";

 public DemoActivity(Context context)
   {
    super(context);
    this.context = context;

   }


    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    setText(firstText);
    setTextSize(30);
    canvas.skew(1.0f, 0.3f);  //you need to change values over here
    Rotate3dAnimation skew = new Rotate3dAnimation(
              -20, 30,200, 200, 0, false);   //here too
    startAnimation(skew);

        }
    }

次のような出力が得られました。

ここに画像の説明を入力

試行錯誤で値を変更すると、問題を解決できると思います。それが役に立てば幸い。

于 2012-07-08T05:55:45.637 に答える
0

Parth Doshiの回答に感謝します。彼の答えは、他の誰かの時間を節約するためにここで共有しているものを実行するために少し調整する必要があります。

最初に src フォルダーにクラスを作成し、3 つのコンストラクターすべてを記述します。

public class TextViewDemo extends TextView {

Context context;
String text = "TESTING 3DX TOOLS";

public TextViewDemo(Context context) {
    super(context);
    this.context = context;
}

public TextViewDemo(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
}

public TextViewDemo(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.context = context;
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    setText(text);
    setTextSize(30);
    canvas.skew(0.5f, 1.0f); // you need to change values over here
    Rotate3dAnimation skew = new Rotate3dAnimation(-50, 30, 0, 0, 0,
            false); // here too
    startAnimation(skew);

}

}

res/layout/my_layout.xml ファイルで、カスタムメイドの TextView のタグを追加できます。

<com.yourpackage.name.TextViewDemo
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Hello World"
<!-- All parameters and value shall remain same -->
/>

他のビューと同様に、 onCreate() メソッドで TextViewDemo のインスタンスを作成できます。

TextViewDemo txtDemo = (TextViewDemo) findViewById(R.id.name);

よろしく

于 2014-05-25T08:40:54.970 に答える