6

カードの前半だけが表示され、残りの半分が次のトランプで覆われるように、ゲーム内のトランプをオーバーラップさせようとしています。完全に見えるはずのカードは、最後/右端のカードだけです。

次のコードをframelayoutとrelativelayoutの両方で使用しましたが無駄になりました。誰かがいくつかの提案を提供できますか?

public int shouldShow(int numberOfCards, int card, int id)
{
    if(card == -1)
        hide(id);
    else
    {
        findViewById(id).setBackgroundDrawable(deckimages[card]);
        //findViewById(id).offsetLeftAndRight(findViewById(id).getWidth()* numberOfCards / 2);
        show(id);
        //findViewById(id).setPadding(findViewById(id).getWidth()* numberOfCards / 2, 0,0,0);
        return numberOfCards+1;
    }
    return numberOfCards;
}

パディングとオフセットの方法を試してみましたが、どちらも機能していません。しかし、getwidth()メソッドとgetmeasuredwidth()メソッドが0を返していることにも気づきました。

どのレイアウトを使用する必要があるのか​​、getwidth関数が機能しない理由についての提案はありますか?

xmlコードは以下のとおりです...これよりも多くの画像がありますが、これは私がテストしていたものです

<RelativeLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/RelativeLayout1">
            <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
            <ImageView android:id="@+id/imageView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
        </RelativeLayout>
4

2 に答える 2

8

私は何年もの間これに固執し、4時間後にコードとグーグルをいじりました。私はついに解決策を見つけました、そしてそれはかなり簡単です。

次のカードを前のカードの左上に揃えるだけです。これにより、2枚目のカードが前のカードの上に配置されるようになります。次にleftMargin、カードを右上に向かって「押す」ように設定し、部分的なオーバーラップ効果を作成します。

これが私のコードです(プログラムで実行):

for(int i=0; i<hand.size();i++){
        int c = hand.get(i).getCardResource();
        ib = new ImageButton(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_TOP, i-1);
        params.addRule(RelativeLayout.ALIGN_LEFT,i-1);
        params.leftMargin= 40;
        ib.setImageResource(c);
        ib.setClickable(true);
        ib.setPadding( 3, 3, 3, 3);
        ib.setId(i);    
        ib.setLayoutParams(params);
        ll.addView(ib);

    }
于 2013-02-04T21:47:43.583 に答える
1

意図的に画像サイズと一致しないビュー境界を提供し、ImageviewのScaleTypeを使用できます:http://developer.android.com/reference/android/widget/ImageView.ScaleType.html。例えば、android:scaleType="fitStart"

于 2011-10-27T16:07:14.160 に答える