[英]How to scale a View without it taking up the space it would have taken if I didn't scale it?
我試圖使View
看起來與通常的外觀完全一樣,只是尺寸較小。 我嘗試這樣做:
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(getBaseContext());
final Button b1 = new Button(getBaseContext());
final Button b2 = new Button(getBaseContext());
final Button b3 = new Button(getBaseContext());
b1.setText("button 1");
b2.setText("button 2");
b3.setText("button 3");
b2.setScaleX(0.5f);
b2.setScaleY(0.5f);
ll.addView(b1);
ll.addView(b2);
ll.addView(b3);
setContentView(ll);
}
}
它確實縮放了View
,但是仍然占用了我完全不縮放的空間:
我想擺脫按鈕2周圍的不可見空間。3個按鈕在LinearLayout
應該緊湊。
button2在設置比例尺之前被測量.button2的寬度和高度是在設置比例尺之前調用onmeasure時生成的,因此這樣做無法獲得正確的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.