android 2.3:页面元素不可点击
大家好,我是 Android 编程新手(2 个月),所以我希望你们能原谅我愚蠢的问题,这让我疯狂了好几个小时。我开发了一个应用程序,其首页有以下登录表单:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:scrollbars="vertical" android:scrollbarStyle="insideOverlay" android:layout_height="fill_parent" android:scrollbarAlwaysDrawVerticalTrack="true" android:gravity="top" android:id="@+id/LinearLayoutConnect" android:paddingTop="0px" android:paddingLeft="20px" android:paddingRight="10px" android:paddingBottom="20px">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbarSize="10px" android:scrollbarStyle="insideOverlay" android:addStatesFromChildren="true" android:id="@+id/ScrollView03">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/LinearLayout02">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/connect" android:paddingTop="25px">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal">
<TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.envCode" android:id="@+id/label_env" android:textColor="#fff" android:layout_weight="33"></TextView>
<EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/env" android:layout_weight="67"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingTop="15px">
<TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.email" android:id="@+id/label_login" android:textColor="#fff" android:layout_weight="33"></TextView>
<EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/login" android:layout_weight="67"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingTop="15px">
<TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.password" android:id="@+id/label_password" android:textColor="#fff" android:layout_weight="33"></TextView>
<EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/password" android:password="true" android:layout_weight="67"></EditText>
</LinearLayout>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:enabled="true" android:text="@string/connect.remember" android:id="@+id/che_user_save" android:layout_gravity="center" android:paddingTop="20px"></CheckBox>
<TableLayout android:id="@+id/TableLayoutconnect" android:layout_height="wrap_content" android:visibility="visible" android:layout_width="fill_parent" android:paddingTop="20px">
<TableRow android:id="@+id/TableRowconnect01" android:layout_height="wrap_content" android:layout_width="fill_parent">
<Button android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.connect" android:id="@+id/auth_button_connect" android:layout_weight="52"></Button>
<Button android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/global.reset" android:id="@+id/auth_button_reset" android:layout_weight="48"></Button>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/connect.link" android:width="266sp" android:gravity="center" android:layout_marginTop="20sp" android:padding="4sp" android:background="#fe0000" android:textColor="#ffffff" android:id="@+id/PromoBar" ></TextView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/disconnect">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/global.disconnect" android:id="@+id/auth_button_disconnect" android:layout_weight="60"></Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
这是相关的 Java 代码:
env = (EditText) findViewById(R.id.env);
txt_login = (EditText) findViewById(R.id.login);
txt_password = (EditText) findViewById(R.id.password);
but_connect = (Button) findViewById(R.id.auth_button_connect);
but_connect.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
XMLRPC_connect();
}
});
but_reset = (Button) findViewById(R.id.auth_button_reset);
but_reset.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
try {
ClearSettings(getBaseContext(),filename_settings);
env.setText("");
txt_login.setText("");
txt_password.setText("");
} catch(Exception e) {}
}
});
问题是: 在以前的 Android 版本(最高 2.2)中,所有按钮和 EditText 字段都是完全可点击和可编辑的。
在 Android 2.3 上(在 Eclipse 下使用模拟器 - 没有真正的设备),屏幕对触摸或单击完全不敏感:无法选择和突出显示屏幕上的任何元素,只能使用轨迹球或键盘来执行此操作,结果非常烦人。屏幕本身不可滚动。
我尝试强制所有 TextEdit 字段和按钮可编辑、可聚焦或可单击,我尝试更新 Eclipse ADT,我尝试使用 Android 2.3 库编译项目,...没有结果。无论我点击哪个元素,它的 onClick 函数都不会被触发......我真的没有解决方案了!感谢您的帮助!
Hello everybody I am pretty new at Android programming (2 months), so I hope you'll forgive my silly question, which has made me crazy for hours. I have developed an application having as a first page the following login form:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:scrollbars="vertical" android:scrollbarStyle="insideOverlay" android:layout_height="fill_parent" android:scrollbarAlwaysDrawVerticalTrack="true" android:gravity="top" android:id="@+id/LinearLayoutConnect" android:paddingTop="0px" android:paddingLeft="20px" android:paddingRight="10px" android:paddingBottom="20px">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbarSize="10px" android:scrollbarStyle="insideOverlay" android:addStatesFromChildren="true" android:id="@+id/ScrollView03">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/LinearLayout02">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/connect" android:paddingTop="25px">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal">
<TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.envCode" android:id="@+id/label_env" android:textColor="#fff" android:layout_weight="33"></TextView>
<EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/env" android:layout_weight="67"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingTop="15px">
<TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.email" android:id="@+id/label_login" android:textColor="#fff" android:layout_weight="33"></TextView>
<EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/login" android:layout_weight="67"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingTop="15px">
<TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.password" android:id="@+id/label_password" android:textColor="#fff" android:layout_weight="33"></TextView>
<EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/password" android:password="true" android:layout_weight="67"></EditText>
</LinearLayout>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:enabled="true" android:text="@string/connect.remember" android:id="@+id/che_user_save" android:layout_gravity="center" android:paddingTop="20px"></CheckBox>
<TableLayout android:id="@+id/TableLayoutconnect" android:layout_height="wrap_content" android:visibility="visible" android:layout_width="fill_parent" android:paddingTop="20px">
<TableRow android:id="@+id/TableRowconnect01" android:layout_height="wrap_content" android:layout_width="fill_parent">
<Button android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.connect" android:id="@+id/auth_button_connect" android:layout_weight="52"></Button>
<Button android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/global.reset" android:id="@+id/auth_button_reset" android:layout_weight="48"></Button>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/connect.link" android:width="266sp" android:gravity="center" android:layout_marginTop="20sp" android:padding="4sp" android:background="#fe0000" android:textColor="#ffffff" android:id="@+id/PromoBar" ></TextView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/disconnect">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/global.disconnect" android:id="@+id/auth_button_disconnect" android:layout_weight="60"></Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
This is the related Java code:
env = (EditText) findViewById(R.id.env);
txt_login = (EditText) findViewById(R.id.login);
txt_password = (EditText) findViewById(R.id.password);
but_connect = (Button) findViewById(R.id.auth_button_connect);
but_connect.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
XMLRPC_connect();
}
});
but_reset = (Button) findViewById(R.id.auth_button_reset);
but_reset.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
try {
ClearSettings(getBaseContext(),filename_settings);
env.setText("");
txt_login.setText("");
txt_password.setText("");
} catch(Exception e) {}
}
});
The question is:
In the previous versions of Android (up to 2.2) all the buttons and EditText fields are perfectly clickable and editable.
On Android 2.3 (using an emulator under Eclipse - don't have a real device) the screen is totally insensitive to touch or click: no element on it can be selected and highlighted, it's possible to do so only using the trackball or the keyboard, resulting to be pretty annoying. The screen itself is not scrollable.
I tried to force all TextEdit fields and Buttons editable, focusable or clickable, I tried to update Eclipse ADT, I tried to compile the project with Android 2.3 libraries,... no result. Whatever element I click on, its onClick function is never triggered... I've really run out of solutions! Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有三个建议:
connect
和disconnect
的 LinearLayout 它们都是垂直的并且嵌入在 idLinearLayout02 的垂直 LinearLayout 中
。结果应该是一样的。onTouchEvent
并检查触摸屏幕时是否调用此事件。从此开始逐步深入布局。I have three advices:
connect
anddisconnect
they are both vertical and embedded in a vertical LinearLayout with idLinearLayout02
. The result should be the same.onTouchEvent
in the activity and check if this is called when you touch the screen. From there on go deeper in the layout step by step.