私は "&を殺す"のようなゲームを作ろうとしています。私はそのキャラクターが殺すための健康バーを作ろうとしています。 シンプルな画像(赤い四角形)を使用しています。ワンクリック後にヘルスバーを縮小したいと思います。私が試したものは動作しますが、問題はただの減少でもなく、高さでもありません。結果は本当に恐ろしいです。これは私のXMLで、開始するには(私は例えば1見せる):比例関係ではなく画像のサイズを変更するには?
だからここ<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="33">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF00"
android:id="@+id/hole4"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/healthBar4"
android:src="@drawable/health_bar"/>
</RelativeLayout>
悪い何もない(と思う)私は、問題はここから来たと思ったので、私はandroid:adjustViewBounds="true"
を残します。私は誰かがいない比例画像サイズを変更する方法を知っている願っています
final int healthBarHeightInitial = healthBar4.getLayoutParams().height;
final int healthBarWidthInitial = healthBar4.getLayoutParams().width;
healthBar4.requestLayout();
//ivHole4 is my ImageView I get the click to leave some life to the character
ivHole4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//If character die (works great).
if(choixAction.ChoixAction(CharaHole4,outil)){
Log.d("Perso","Character is die");
mAvancement +=1;
ivHole4.setImageResource(0);
CharaHole4 = null;
placeChara.setHole4(true);
healthBar4.setVisibility(View.GONE);
healthBar4.getLayoutParams().height = healthBarHeightInitial;
healthBar4.getLayoutParams().width = healthWidthInitial;
}
//if character don't die (here is the problem !)
else {
healthBar4.getLayoutParams().width = healthBar4.getWidth()/2; //This is works great
healthBar4.getLayoutParams().height = healthBarHeightInitial; //This is do nothing, the height is /2 too.
healthBar4.requestLayout();
}
}
});
: 次は私の活動です。 ありがとうございます。
ImageViewにこれを追加しようとしましたか? :android:scaleType = "fitXY" ' – Knossos
それは動作します! =)ありがとうございました!もし私があなたの答えを最良の答えにしたい場合は、新しいメッセージを投稿してください。 – LeNomade