android工程中资源模块划分

来源:互联网 发布:知其所以然 编辑:程序博客网 时间:2024/05/15 03:49

android app中的资源管理:所有的资源都位于res目录下。

1,图片资源(drawable-hdpi和drawable-mdpi

不像游戏,所有图片都是在assets下面的,app中为了屏幕适配,图片资源是在drawable-hdpi和drawable-mdpi下面的。

2,按钮按下各种状态。(drawable)

实例

news_collect_btn_selector.xml

<?xml version="1.0" encoding="UTF-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_focused="true"android:drawable="@drawable/news_collect_btn_press" /><itemandroid:state_pressed="true"android:drawable="@drawable/news_collect_btn_press" /><itemandroid:drawable="@drawable/news_collect_btn" /></selector>

news_reply_post_btn_selector.xml

<?xml version="1.0" encoding="UTF-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_enabled="false"android:drawable="@drawable/news_reply_post_btn_up" /><itemandroid:state_pressed="true"android:drawable="@drawable/news_reply_post_btn_down" /><itemandroid:state_focused="true"android:drawable="@drawable/news_reply_post_btn_down" /></selector>

其中@drabable下面的引用是drawable-hdpi和drawable-mdpi下面的图片资源。

3,颜色(color)

category_item_title_selector.xml

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_pressed="true"android:color="#ffffffff" /><itemandroid:state_focused="true"android:color="#ffffffff" /><itemandroid:state_selected="true"android:color="#ffffffff" /><itemandroid:color="#ffadb2ad" /></selector>
newslist_item_source_selector.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_pressed="false"android:color="#ff878787" /><itemandroid:state_pressed="true"android:color="#ffbcbcbc" /><itemandroid:state_focused="true"android:color="#ffbcbcbc" /><itemandroid:color="#ff878787" /></selector>
4,动画(anim)

push_left_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="500"        android:fromXDelta="100.0%p"        android:toXDelta="0.0" />    <alpha        android:duration="500"        android:fromAlpha="0.1"        android:toAlpha="1.0" /></set>
push_left_out.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="500"        android:fromXDelta="0.0"        android:toXDelta="-100.0%p" />    <alpha        android:duration="500"        android:fromAlpha="1.0"        android:toAlpha="0.1" /></set>

push_right_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="500"android:fromXDelta="-100.0%p"android:toXDelta="0.0" /><alphaandroid:duration="500"android:fromAlpha="0.1"android:toAlpha="1.0" /></set>
push_right_out.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="500"android:fromXDelta="0.0"android:toXDelta="100.0%p" /><alphaandroid:duration="500"android:fromAlpha="1.0"android:toAlpha="0.1" /></set>
5,各种自定义界面(layout)

main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@id/main_layout"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/main_background"    >    <RelativeLayout        android:id="@id/titlebar_layout"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@drawable/titlebar_background"        >        <TextView             android:id="@id/titlebar_title"        android:layout_width="wrap_content"        android:layout_height="wrap_content"            android:textSize="23.0sp"        android:layout_marginTop="9.0dip"        android:layout_marginLeft="10.0dip"        android:text="@string/app_name"        />        <Button        android:id="@id/titlebar_refresh"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/titlebar_btn_refresh_selector"        android:layout_alignParentRight="true"        android:layout_marginTop="7.0dip"        android:layout_marginRight="14.0dip"        />                <ProgressBarandroid:id="@id/loadnews_progress"android:layout_width="25.0dip"android:layout_height="25.0dip"android:clickable="false"android:visibility="gone"android:layout_marginRight="20.0dip"android:layout_marginTop="10.0dip"android:layout_alignParentRight="true"style="?android:attr/progressBarStyleLarge" />    </RelativeLayout>         <RelativeLayout        android:id="@id/categorybar_layout"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@drawable/categorybar_background"        android:layout_marginTop="-15dip"        ><HorizontalScrollView     android:id="@id/category_scrollview"    android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginLeft="6.0dip"android:scrollbars="none"android:layout_toLeftOf="@id/category_arrow_right"android:layout_centerVertical="true">            <LinearLayout                android:id="@id/category_layout"                android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:gravity="center_vertical"        android:orientation="vertical"        /></HorizontalScrollView><Buttonandroid:id="@id/category_arrow_right"android:layout_width="6.0dip"android:layout_height="10.0dip"android:background="@drawable/categorybar_right_arrow"android:layout_marginLeft="2.0dip"android:layout_marginRight="10.0dip"android:layout_alignParentRight="true"android:layout_centerVertical="true" />    </RelativeLayout>   <ListView     android:id="@id/newslist"    android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:listSelector="@drawable/newslist_item_selector"        android:cacheColorHint="#00000000"        android:divider="@drawable/list_separator_line"    /></LinearLayout>
6,各种全局变量(values)

arrays.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <string-array name="categories">        <item>1|关于我们</item>        <item>2|新闻中心</item>        <item>3|中天产品</item>        <item>4|中天证券</item>        <item>5|技术支持</item>        <item>6|市场服务</item>        <item>7|人才招聘</item>        <item>8|在线咨询</item>        <item>9|中天家园</item>        <item>10|预警平台</item>        <item>11|联系我们</item>    </string-array></resources>
color.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <item type="drawable" name="main_background">#ffe7e7e7</item>    <item type="color" name="white">#ffffffff</item>    <item type="drawable" name="newslist_item_background">#ffe7e7e7</item><item type="drawable" name="category_title_normal_background">#ffadb2ad</item></resources>

ids.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <item type="id" name="main_layout"/>    <item type="id" name="titlebar_layout"/>    <item type="id" name="titlebar_title"/>    <item type="id" name="titlebar_refresh"/>    <item type="id" name="loadnews_progress"/>    <item type="id" name="categorybar_layout"/>    <item type="id" name="category_arrow_right"/>    <item type="id" name="category_scrollview"/>    <item type="id" name="category_layout"/>    <item type="id" name="newslist"/>    <item type="id" name="category_title"/>    <item type="id" name="newslist_item_info_layout"/>    <item type="id" name="newslist_item_title"/>    <item type="id" name="newslist_item_digest"/>    <item type="id" name="newslist_item_source"/>    <item type="id" name="newslist_item_ptime"/>    <item type="id" name="newslist_item_go_detail"/>    <item type="id" name="newsdetails_layout"/>    <item type="id" name="newsdetails_titlebar_layout"/>    <item type="id" name="newsdetails_titlebar_previous"/>    <item type="id" name="newsdetails_titlebar_title"/>    <item type="id" name="newsdetails_titlebar_next"/>    <item type="id" name="newsdetails_titlebar_comments"/>    <item type="id" name="news_body_layout"/>    <item type="id" name="news_body_scrollview"/>    <item type="id" name="news_body_title"/>    <item type="id" name="news_body_ptime_source"/>    <item type="id" name="news_body_separator_line"/>    <item type="id" name="news_body_details_loading"/>    <item type="id" name="news_body_details"/>    <item type="id" name="news_reply_layout"/>    <item type="id" name="news_reply_edit_layout"/>    <item type="id" name="news_reply_edittext"/>    <item type="id" name="news_reply_post"/>    <item type="id" name="news_reply_img_layout"/>    <item type="id" name="news_reply_img_btn"/>    <item type="id" name="news_share_btn"/>    <item type="id" name="news_collect_btn"/>    <item type="id" name="news_body_flipper"/>    <item type="id" name="comments_layout"/>    <item type="id" name="comments_titlebar_layout"/>    <item type="id" name="comments_titlebar_title"/>    <item type="id" name="comments_titlebar_count"/>    <item type="id" name="comments_titlebar_news"/>    <item type="id" name="comments_titlebar_progressbar"/>    <item type="id" name="comments_list"/>    <item type="id" name="comments_reply_frame"/>    <item type="id" name="commentator_from"/>    <item type="id" name="comment_ptime"/>    <item type="id" name="comment_content"/>    <item type="id" name="loadmore_layout"/>    <item type="id" name="loadmore_btn"/>    <item type="id" name="loadmore_progress"/>    <item type="id" name="loadmore_txt"/></resources>

strings.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">zttnews</string>    <string name="action_settings">Settings</string>    <string name="hello_world">Hello world!</string>    <string name="loadmore_btn">加载更多</string>    <string name="loadmore_txt">正在加载,请稍候...</string>    <string name="no_news">该栏目下暂时没有新闻</string>    <string name="no_more_news">该栏目下没有更多新闻</string>    <string name="load_news_failure">获取新闻失败</string>    <string name="no_next_news">没有下篇新闻了</string>    <string name="no_pre_news">没有上篇新闻了</string></resources>





0 0
原创粉丝点击