您的位置:首页 > 移动开发 > Android开发

android.R.layout.simple_spinner_dropdown_item和android.R.layout.simple_spinner_item到底是啥意思?

2015-10-22 14:09 337 查看
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

private String[] items= {"lorem", "ipsum", "dolor", "sit", "amet",….

ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);

spin.setAdapter(aa);

都提到了R.layout,这到底是啥?
看sdk下的sdk\platforms\android-18\data\res\layout下有很多的文件


 
打开simple_spinner_item.xml看看

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");

** you may not use this file except in compliance with the License.

** You may obtain a copy of the License at

**
**
http://www.apache.org/licenses/LICENSE-2.0

**
** Unless required by applicable law or agreed to in writing, software

** distributed under the License is distributed on an "AS IS" BASIS,

** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

** See the License for the specific language governing permissions and

** limitations under the License.
*/
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:textAlignment="inherit"/>

打开simple_spinner_dropdown_item.xml文件看看
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");

** you may not use this file except in compliance with the License.

** You may obtain a copy of the License at

**
**
http://www.apache.org/licenses/LICENSE-2.0

**
** Unless required by applicable law or agreed to in writing, software

** distributed under the License is distributed on an "AS IS" BASIS,

** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

** See the License for the specific language governing permissions and

** limitations under the License.
*/
-->
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/dropdownListPreferredItemHeight"
    android:ellipsize="marquee"
    android:textAlignment="inherit"/>

看看android的api文档里也提到了这两个家伙


 
原来是使用自带的xml啊,那就可以自定义Spinner的Layout,替换掉体统默认的android.R.layout.simple_spinner_item。
请参考http://www.blogjava.net/crazycoding/archive/2011/07/09/353981.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: