lixiaoyi666

android仿微信首页UI设计

首先介绍效果图:

然后详细介绍过程以及遇到的问题:

1、新建一个安卓空工程

为了实现上图的效果我们采用ListView布局

注:LinerLayout+ListView可以实现线性条目的效果

2、我们要使用适配器达到界面滚动的效果

其上半部分:

新建一个MainActivity2可以实现界面跳转功能

效果如图:

3、为了更像微信,我们可以添加图片

  • 首先将图片放入drawable(注意取名字只能小写!)

导入图片之后,我们要显示图片,那么怎么显示图片呢?android系统的适配器貌似没有可以显示图片的,所以我们要自定义适配器,所以之前的代码要做稍稍的改动

首先:我们创建一个类命名为Test,这个类的功能就是自定义类型,并实现一些功能

然后:把类型改为Test类型,并利用Test类来获取名字

最后:我们自定义适配器来完成布局

  • 我们建一个TestAdapter类,目的是重写getView方法,以便显示图片

效果图:

为了使图片跟文字可控,我们可以建一个layout

画线部分是使图片填充整个区域并设置id以便调用

4、界面跳转和评论

  • 为了实现界面跳转,我们新建一个MainActivity2

  • 在activity_main2.xml中改写如下:

  • <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        tools:context=".MainActivity2">
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_gravity="bottom"
                android:background="#FFFFFF"
                android:orientation="vertical"
                android:paddingLeft="10dp"
                android:paddingRight="10dp">
    
                <TextView
                    android:id="@+id/activity2_Text1"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_marginBottom="100dp"
                    android:layout_marginLeft="150dp"
                    android:text="Hello World!"
                    android:textSize="30sp"
                    android:textStyle="bold" />
                <EditText
                    android:id="@+id/activity2_Edi1"
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:background="#f0f0f0"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:gravity="left|top"
                    android:hint="我來說一說~"
                    android:paddingBottom="5dp"
                    android:paddingLeft="8dp"
                    android:paddingRight="8dp"
                    android:paddingTop="5dp"
                    android:textSize="14dp"/>
                <Button
                    android:id="@+id/activity2_Btn1"
                    android:text="发表评论"
                    android:layout_gravity="right"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    />
                <TextView
                    android:text="@string/activity2_text2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
    
  • 这里布局就完成了一个,然后我们去实现点击跳转和评论替换HelloWorld

  • 点击跳转:写在第2、点

  • 评论替换HelloWorld:

  • 红框部分就是实现按键评论替换替换HelloWorld

    效果图:

至此,大功告成,

完结,撒花!!

-- 赋程序链接:
-- 链接:https://pan.baidu.com/s/1IC7oOUravQn4w5FqzSFs1Q
提取码:6666
复制这段内容后打开百度网盘手机App,操作更方便哦

分类:

技术点:

相关文章:

  • 2021-04-17
  • 2022-12-23
  • 2021-10-21
  • 2021-08-10
  • 2022-01-10
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2021-08-16
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-12-27
  • 2022-02-14
相关资源
相似解决方案