我正在尝试制作一个像“点击并杀死”的游戏,而我正试图为角色制作一个健康栏。 我正在使用一个简单的图像(一个红色矩形),我想在一次点击后减少健康状况。我尝试过的是有效但问题不仅仅是减少,高度也是如此。结果真是太可怕了。首先,这是我的XML(我只展示了一个例子):
<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();
}
}
});
我希望有人知道如何不按比例更改图像大小。 谢谢你的进步。
答案 0 :(得分:0)
使用Picasso Library并设置裁剪中心。
答案 1 :(得分:0)
您在XML布局中的DECLARE @OBJ_TBLNAME VARCHAR(100) = 'touchnet'
DECLARE @OUTTBL AS TABLE (NAME VARCHAR(200), DATATYPE VARCHAR(200), NULLABLE VARCHAR(10))
declare @mytbl as table(TABLE_NAME VARCHAR(500))
INSERT INTO @mytbl SELECT TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_CATALOG=@OBJ_TBLNAME GROUP BY TABLE_NAME
WHILE((SELECT COUNT(*) FROM @mytbl)>0)
BEGIN
DECLARE @TBLNAME VARCHAR(200)
SELECT TOP 1 @TBLNAME = TABLE_NAME FROM @mytbl GROUP BY TABLE_NAME
INSERT INTO @OUTTBL(NAME, DATATYPE, NULLABLE) SELECT @TBLNAME, '', ''
INSERT INTO @OUTTBL(NAME, DATATYPE, NULLABLE) SELECT 'Colum Name', 'Data Type', 'Type'
INSERT INTO @OUTTBL
select COLUMN_NAME AS NAME, CONVERT(varchar, DATA_TYPE) + (case when ISNULL(CHARACTER_MAXIMUM_LENGTH,-1)=-1 then '' else '('+CONVERT(varchar, CHARACTER_MAXIMUM_LENGTH)+')' end) AS DATATYPE, (CASE when is_nullable = 'YES' then 'NOT NULL' else 'NULL' end) AS NULLABLE from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG=@OBJ_TBLNAME and TABLE_NAME=@TBLNAME
INSERT INTO @OUTTBL(NAME, DATATYPE, NULLABLE) SELECT '', '', ''
DELETE TOP(1) FROM @mytbl
END
SELECT * FROM @OUTTBL
需要将比例类型设置为ImageView
,以便在不保持比例的情况下进行扩展。
fitXY