我刚刚将Android SDK更新至版本18,并修改了我正在使用它而不是版本17的项目。事实证明,我的ListView现在看起来很不一样。但是,只需在清单文件中将targetSdkVersion从18更改为17即可。ListView项目布局在targetSdkVersion =“17”和targetSdkVersion =“18”之间不相同
我设法在Eclipse中创建一个新的Android项目和改变的主要活动最基本的ListActivity执行可能重现该问题:
public class MainActivity extends ListActivity {
private static final String[] listItems = new String[] { "list item 1", "list item 2"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.text, listItems));
}
}
的list_item.xml文件包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="100dip"
android:background="#ff0000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/text"
android:layout_alignTop="@id/text"
android:background="#88ffffff"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#8c0000ff"
android:text="@string/button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dip"
android:background="#8c00ff00"
android:text="@string/button2" />
</LinearLayout>
</RelativeLayout>
将LinearLayout放在TextView上是有意的。我想使用LinearLayout作为覆盖层,并在必要时显示/隐藏它。
现在,当我将AndroidManifest.xml文件中的targetSdkVersion设置为17时,一切都按预期工作,这意味着按钮与LinearLayout的高度相匹配。但是,当我将版本切换到18时,它们的行为就像使用“wrap_content”一样。为什么我得到这种奇怪的行为,我如何修复它在SDK 17中的工作?
我有与视图高度相同的问题。我不知道如何解决这个问题。我会留在api 17级 – passsy