zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Android:新闻类应用布局、分割线

Android应用 布局 新闻 分割线
2023-09-14 09:01:37 时间

想做一个新闻类应用,类似今日资讯
先上效果
在这里插入图片描述
每篇文章之间的分割线有两种思路可以做
第一种,背景灰色,设置卡片间距
第二种,直接用shape画
这里采用第二种方法

首先在drawable里面建dash_line文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >

    <!--线宽为dashWith,线之间空隙dashGap,dashGap=0dp时,是实线 -->
    <stroke
        android:dashGap="0dp"
        android:dashWidth="30dip"
        android:width="1dip"
        android:color="@android:color/darker_gray" />

    <!-- 虚线高度 -->
    <size android:height="1dip" />

</shape>

之后在布局中引入

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/white">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dp">

            <ImageView
                android:layout_width="10dp"
                android:layout_height="100dp"
                android:scaleType="fitXY"
                android:layout_weight="1"
                android:src="@drawable/pc1"></ImageView>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="这是文章标题"
                    android:textSize="30dp"
                    android:textStyle="bold"
                    android:textColor="@color/black"
                    android:paddingLeft="10dp"></TextView>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="作者:"
                    android:textSize="25dp"
                    android:paddingLeft="10dp"
                    ></TextView>

            </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:background="@drawable/dash_line"
            android:layerType="software"
            android:orientation="horizontal" />

    </LinearLayout>

想要多个,多复制几个即可

参考资料:Android分割线divider