【发布时间】:2012-01-20 01:09:13
【问题描述】:
您好,我一直在努力解决这个问题,但我做不到。我有这个按钮
<Button android:layout_alignLeft="@+id/button1" android:layout_below="@+id/button2"
android:id="@+id/button3"
android:layout_width="235dp"
android:text="@string/spire"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
>
当这个按钮出现在较小的屏幕上时,我怎样才能使它的按钮也缩小自己的尺寸?谢谢!
编辑:好的,这是新代码。但是我不确定如何使编辑功能起作用?我有进口的东西吗?
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.view.View;
import android.content.Intent;
import android.content.SharedPreferences;
import android.widget.Button;
public void getDisplay(){
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
case DisplayMetrics.DENSITY_LOW:
edit.putInt("SIZE", 12).commit();
edit.putInt("POSITION", -8).commit();
break;
case DisplayMetrics.DENSITY_MEDIUM:
edit.putInt("SIZE", 16).commit();
edit.putInt("POSITION", -6).commit();
break;
case DisplayMetrics.DENSITY_HIGH:
edit.putInt("SIZE", 25).commit();
edit.putInt("POSITION", 8).commit();
break;
case DisplayMetrics.DENSITY_XHIGH:
//edit.putInt("SIZE",35).commit();
//edit.putInt("POSITION",30);
break;
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
goHereButton = (Button) findViewById(R.id.button1);
goHereButton.setWidth(20);
goHereButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
Intent i = new Intent(UMassGuide.this, DirectionsScreenActivity.class);
startActivity(i);
}
});
还有我该怎么做 xml 文件?我要删除宽度吗?
【问题讨论】: