Bar*_*tek 5 android android-listview
我刚刚将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)
在TextView上使用LinearLayout是有意的.我想使用LinearLayout作为叠加层,并在必要时显示/隐藏它.
现在,当我将AndroidManifest.xml文件中的targetSdkVersion设置为17时,一切都按预期工作,这意味着按钮与LinearLayout的高度匹配.但是,当我将版本切换为18时,它们就像使用"wrap_content"一样.为什么我会遇到这种奇怪的行为?如何在SDK 17中修复它?
这对我来说似乎很奇怪。据我所知,您的 LinearLayout 不需要设置layout_alignBottom/layout_alignTop 属性,但是删除这些行,LinearLayout 本身也会显示错误。我能得到我认为在我的测试中想要的结果的唯一方法是从 LinearLayout 中删除alignTop/alignBottom(因为这些似乎不必要)并添加以下行:
android:minHeight="100dip"
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
273 次 |
| 最近记录: |