如何覆盖和使用音量按钮缩放布局中的IN / OUT文本,类似于编写/阅读短信时的内容?
答案 0 :(得分:0)
请检查此解决方案。
public class MainActivity extends AppCompatActivity {
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView) findViewById(R.id.OpenClose);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
float x = txt.getScaleX();
float y = txt.getScaleY();
txt.setScaleX(x - 1);
txt.setScaleY(y - 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
float x = txt.getScaleX();
float y = txt.getScaleY();
txt.setScaleX(x + 1);
txt.setScaleY(y + 1);
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
}