【发布时间】:2011-12-05 08:41:43
【问题描述】:
我的应用程序中有以下布局,最低 API 级别为 4,目标 API 级别为 8。事实是,在某些设备(例如 Xperia X10 mini)中,当我触摸 @+actBula/btnZoomOut 时,采取的操作是从其侧面的按钮@+actBula/btnZoomIn。而在 Xperia X8 和其他三星手机中,它运行良好。
Xperia X10 mini 的规格为 240 x 320 像素,2.55 英寸(约 157 ppi 像素密度)。 Xperia X8 为 320 x 480 像素,3.0 英寸(约 192 ppi 像素密度)。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/linearLayout1" android:scrollbarAlwaysDrawVerticalTrack="true" android:layout_width="fill_parent">
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="fill_parent">
<LinearLayout android:id="@+id/linearLayout4" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="left">
<Button android:id="@+actBula/btnBack" android:layout_height="wrap_content" android:layout_width="wrap_content" android:paddingLeft="10dp" android:paddingTop="10dp" android:layout_marginLeft="10dp" android:background="@drawable/setabola48" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"></Button>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout5" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="right" android:layout_gravity="right" android:orientation="horizontal" android:layout_marginLeft="50dp">
<Button android:id="@+actBula/btnZoomIn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/zoomp48" android:layout_marginTop="5dp"></Button>
<Button android:id="@+actBula/btnZoomOut" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="20dp" android:background="@drawable/zoomm48" android:layout_marginTop="5dp"></Button>
</LinearLayout>
</LinearLayout>
<ScrollView android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout2" android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:layout_width="wrap_content" (...) ></TextView>
</LinearLayout>
</ScrollView>
这些是 onClick 监听器:
final TextView myTextView = (TextView) findViewById(R.actBula.txtBula);
Button btnZoomIn = (Button) findViewById(R.actBula.btnZoomIn);
btnZoomIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myTextView.setTextSize(myTextView.getTextSize()+1);
}
});
Button btnZoomOut = (Button) findViewById(R.actBula.btnZoomOut);
btnZoomOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myTextView.setTextSize(myTextView.getTextSize()-1);
}
});
【问题讨论】:
-
你能把你添加
onClick监听器的代码贴出来吗?另外,您是否尝试过在按下按钮时记录实际的方法调用,以确保这不是一个简单的逻辑错误? -
我没有记录,但由于相同的 apk 和 xml 布局在不同设备上的工作方式不同,我猜测这是像素密度问题。