Android学习-新闻客户端养成记(二)

新闻客户端需要的 布局文件

                                          
                            新闻主界面                    侧滑菜单界面                                 图片新闻界面                       视频列表界面
                       
                            天气预报界面                     新闻详情界面    

以上几个界面是项目所需要的核心界面,布局摆放并不怎么难,为了比例协调,我用了很多的layout_weight 属性 ;

控制界面mainWindows.xml  这是项目的主界面布局文件
<pre name="code" class="java"><?xml version="1.0" encoding="utf-8"?>
//<strong style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></strong><pre name="code" class="java" style="display: inline !important;">DrawerLayout  控件可轻松实现侧滑功能 

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawerLayout" android:layout_width="match_parent" android:layout_height="match_parent" >  
   //碎片会显示在这里
    <FrameLayout
        android:id="@+id/frame_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

    <!-- android:layout_gravity="start" -->

    <LinearLayout
        android:id="@+id/menuLayout"
        android:layout_width="200dp"
        android:layout_height="match_parent"
     
        android:layout_gravity="start"   //决定抽屉菜单的位置  start 为左边
        android:background="@color/menu_layout_bg"
        android:clickable="false"
        android:orientation="vertical"
        android:padding="10dp" >

        <RelativeLayout
            android:id="@+id/menuTop"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/userImg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_margin="10dp"
                android:background="@drawable/user_img_shape"
                android:contentDescription="@string/app_name"
                android:src="@drawable/people1" />

            <TextView
                android:id="@+id/userName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@id/userImg"
                android:layout_margin="10dp"
                android:layout_toRightOf="@id/userImg"
                android:text="@string/unLogin"
                android:textSize="20sp" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/menuMain"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/menu_btn_shape"
            android:clickable="true"
            android:orientation="horizontal"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >

            <ImageView
                android:id="@+id/img1"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:src="@drawable/menu_main" />

            <TextView
                android:id="@+id/tv1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="40dp"
                android:text="@string/menu_main"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000" />

        <LinearLayout
            android:id="@+id/menuPic"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/menu_btn_shape"
            android:clickable="true"
            android:orientation="horizontal"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:src="@drawable/menu_pic_icon" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="40dp"
                android:text="@string/menu_picture"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000" />

        <LinearLayout
            android:id="@+id/menuVideo"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/menu_btn_shape"
            android:clickable="true"
            android:orientation="horizontal"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:src="@drawable/menu_video_icon" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="40dp"
                android:text="@string/menu_video"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000" />

        <LinearLayout
            android:id="@+id/menuWeather"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/menu_btn_shape"
            android:clickable="true"
            android:orientation="horizontal"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:src="@drawable/menu_weather_icon" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="40dp"
                android:text="@string/menu_weather"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000" />

        <LinearLayout
            android:id="@+id/menuCollect"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/menu_btn_shape"
            android:clickable="true"
            android:orientation="horizontal"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >

            <ImageView
                android:id="@+id/collectIv"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:src="@drawable/menu_collect" />

            <TextView
                android:id="@+id/collectTv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="40dp"
                android:text="@string/menu_collect"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000" />

        <LinearLayout
            android:id="@+id/menuMore"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/menu_btn_shape"
            android:clickable="true"
            android:orientation="horizontal"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:src="@drawable/menu_more" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="40dp"
                android:text="@string/menu_more"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>


 
 
新闻主页布局文件activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.5"
        android:background="#FFF"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scrollbars="none" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="horizontal" >

                <eNews.customview.ActionBarView 
 
                    android:id="@+id/actionBar"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center" >
                </eNews.customview.ActionBarView>
            </LinearLayout>
        </HorizontalScrollView>

        <TextView
            android:id="@+id/channelManageBtn"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center"
            android:text="@string/add_channel"
            android:textSize="25sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#dadada" >
    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="23.5" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <android.support.v4.view.ViewPager
                android:id="@+id/topViewPager"
                android:layout_width="match_parent"
                android:layout_height="200dp" >
            </android.support.v4.view.ViewPager>

            <eNews.customview.NewsListView      <span style="font-family: Arial, Helvetica, sans-serif;">//使用自定义ListView 避免与 </span><span style="font-family: Arial, Helvetica, sans-serif;">HorizontalScrollView 冲突</span>

                android:id="@+id/newsListView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/list_view_bg"
                android:divider="@color/list_view_divier"
                android:dividerHeight="1dp"
                android:padding="5dp" >
            </eNews.customview.NewsListView>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

图片新闻布局文件picture_news.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:background="@drawable/actionbar_shape"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/backBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_margin="5dp"
            android:background="@drawable/back_btn_shape"
            android:gravity="center" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="@string/picture_title"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFF" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4.5"
        android:background="#FFF"
        android:gravity="center" >

        <eNews.customview.ActionBarView
            android:id="@+id/pictureNewsactionBar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center" >
        </eNews.customview.ActionBarView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#dadada" >
    </LinearLayout>
   //图片新闻列表
    <ListView
        android:id="@+id/pictureList"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="51"
        android:divider="@color/chanel_item_color"
        android:dividerHeight="1dp" >
    </ListView>

</LinearLayout>

视频新闻布局


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:background="@drawable/actionbar_shape"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/backBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:background="@drawable/back_btn_shape"
            android:gravity="center"
            android:padding="5dp" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="@string/video_title"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFF" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4.5"
        android:background="#FFF"
        android:gravity="center" >
        <eNews.customview.ActionBarView
            android:id="@+id/videoNewsactionBar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center" >
        </eNews.customview.ActionBarView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#dadada" >
    </LinearLayout>

    <ListView
        android:id="@+id/videoList"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="51.5" >
    </ListView>

</LinearLayout>


图片详情布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/actionbar_shape"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/backBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_margin="5dp"
            android:background="@drawable/back_btn_shape"
            android:gravity="center" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="@string/picture_detail_title"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFF" />

        <ImageButton
            android:id="@+id/actionbar_more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_margin="5dp"
            android:background="@drawable/actionbar_more_icon"
            android:gravity="center" />
    </RelativeLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pictureViewPager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9" >
    </android.support.v4.view.ViewPager>

</LinearLayout>


新闻详情布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/actionbar_shape"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/backBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_margin="5dp"
            android:background="@drawable/back_btn_shape"
            android:gravity="center" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="@string/news_detail_title"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFF" />
        <ImageButton
            android:id="@+id/actionbar_more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_margin="5dp"
            android:background="@drawable/actionbar_more_icon"
            android:gravity="center" />
    </RelativeLayout>

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/news_detail_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>


自定义ListView 控件 避免与scrollView 冲突
package eNews.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * 
 * @author 王凯
 * @date 2016-9-12 新闻列表控件
 */
public class NewsListView extends ListView {

	public NewsListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}
}
源代码下载
做好以上布局用以后,还是不能显示出数据,因为还没有为列表控件做适配器,现在只是一个空壳而已




猜你喜欢

转载自blog.csdn.net/w1143408997/article/details/52528781