我刚刚将Android SDK更新到版本18并修改了我正在使用它而不是版本17的项目.事实证明我的ListView现在看起来很不一样.但是,只需将清单文件中的targetSdkVersion从18切换到17,即可再次使用.
我设法通过在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));
}
}
Run Code Online (Sandbox Code Playgroud)
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> …Run Code Online (Sandbox Code Playgroud)