当前位置:首页 > 谈天说地

Android简易图片浏览器的实现

34资源网2022-03-31443

闲着没事,花了半个小时用这几天发布的部分内容来做一个android简易图片浏览器小程序,代码设main_activity.xml设计首界面,设计三个按钮并赋予id,然后在mainactivity调用各个btn的id实现set方法,每个方法里实现intent跳转对应的界面即可!代码如下:(main2-3-4activity的代码我就不写了,在建立其mainactivity.java文件时,其xml对直接出来,并且我的mainactivity.java也没有写内容)

main_activity.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"
    tools:context=".mainactivity"
    android:orientation="vertical"
    android:background="@drawable/bj"
 
    >
 
    <textview
 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_margintop="60dp"
        android:textsize="50dp"
        android:textcolor="#ff9800"
        android:text="csdn图片大全" />
<button
    android:id="@+id/btn1"
    android:layout_margintop="40dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="动漫"
    android:textsize="45sp"
    android:textcolor="@color/coloraccent"
 
    />
    <button
        android:id="@+id/btn2"
        android:layout_margintop="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="游戏"
        android:textsize="45sp"
        android:textcolor="@color/coloraccent"
 
        />
    <button
        android:id="@+id/btn3"
        android:layout_margintop="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="美女"
        android:textsize="45sp"
        android:textcolor="@color/coloraccent"
 
        />
 
</linearlayout>

activity_main2.xml

<?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:background="#7a3f51b5"
    android:orientation="vertical">
    <scrollview
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <linearlayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
 
 
            <textview
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="欢迎来到动漫世界"
                android:gravity="center"
                android:textsize="40sp"
                />
            <imageview
                android:background="@drawable/dm"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <imageview
                android:background="@drawable/dm1"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <imageview
                android:background="@drawable/dm2"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <imageview
                android:background="@drawable/dm3"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <imageview
                android:background="@drawable/dm4"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <imageview
                android:background="@drawable/dm5"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <imageview
                android:background="@drawable/dm6"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                />
            <textview
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textsize="40sp"
                android:text="滑到最后一页了哦"
                />
        </linearlayout>
    </scrollview>
</linearlayout>

activity_main3.xml

<?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:background="#ff226f"
    android:orientation="vertical">
    <scrollview
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <linearlayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
 
 
            <textview
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="欢迎来到游戏世界"
                android:gravity="center"
                android:textsize="40sp"
                />
            <imageview
                android:background="@drawable/youxi"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi2"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi3"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi4"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi1"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi5"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi6"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi7"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <imageview
                android:background="@drawable/youxi8"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                />
            <textview
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textsize="40sp"
                android:text="滑到最后一页了哦"
                />
        </linearlayout>
    </scrollview>
</linearlayout>

activity_main4.xml

<?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">
    <scrollview
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <linearlayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
 
 
            <textview
                android:background="#9a86af4c"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="欢迎来到美女世界"
 
                android:gravity="center"
                android:textsize="40sp"
                />
            <imageview
 
                android:background="@drawable/mn1"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn2"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn3"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn4"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn5"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn6"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn7"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn8"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn9"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
            <imageview
                android:background="@drawable/mn10"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                />
 
 
            <textview
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textsize="40sp"
                android:text="滑到最后一页了哦"
                />
        </linearlayout>
    </scrollview>
</linearlayout>

mainactivity,java

package com.example.allphones;
 
 
import androidx.appcompat.app.appcompatactivity;
 
import android.content.intent;
import android.os.bundle;
import android.view.view;
import android.widget.button;
 
public class mainactivity extends appcompatactivity {
private button btn1,btn2,btn3;
    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);
 
        btn1=findviewbyid(r.id.btn1);
        btn2=findviewbyid(r.id.btn2);
        btn3=findviewbyid(r.id.btn3);
                btn1.setonclicklistener(new view.onclicklistener() {
                    @override
                    public void onclick(view v) {
                        intent intent=new intent(mainactivity.this,main2activity.class);
                        startactivity(intent);
            }
        });
        btn2.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view v) {
 
                intent intent=new intent(mainactivity.this,main3activity.class);
                startactivity(intent);
            }
        });
        btn3.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view v) {
 
                intent intent=new intent(mainactivity.this,main4activity.class);
                startactivity(intent);
 
            }
        });
    }
}

 到此这篇关于android简易图片浏览器的实现的文章就介绍到这了,更多相关android 图片浏览器内容请搜索萬仟网以前的文章或继续浏览下面的相关文章希望大家以后多多支持萬仟网!

版权声明:34楼发布

本文链接:https://www.34l.com/post/11469.html

分享给朋友:

相关文章

富人定律:假装自己很有钱的做法,很多时候是必须的

富人定律:假装自己很有钱的做法,很多时候是必须的

1、几年前,我去朋友公司上班,去之前,他给我联系好了住宿——一个离公司特别远的小隔间,两个人合住,每月200多块钱的住宿费。我知道,他是为我好,那正是我缺钱的时候,他觉得我应该尽可能地省钱,就找了这间全城最便宜的住处。但这个小隔间,真的有很…

什么是开关电源?什么是线性电源?两者有什么不同?

什么是开关电源?什么是线性电源?两者有什么不同?

本文将和大家介绍下什么是开关电源?什么是线性电源?对于两者有哪些方面不同不是很了解的朋友,可以好好看下,希望对大家有所帮助。…

用一个仍然造句和用三个仍然造句
100元内最好的音箱选择哪种好?看看这款适合你不?

100元内最好的音箱选择哪种好?看看这款适合你不?

目前市面上的音箱种类繁多,有的音质非常好,有的音质比较差,有些朋友酷爱音乐,可是又不想花太多钱在这些音箱上面,一般都会选择一些100元以内的音箱。那么100元内最好的音箱选择哪种好?下面,小编给大家推荐一款迷你型的小音箱,大家一起来看看吧。…

养成良好的习惯,做一名有品位的教师

养成良好的习惯,做一名有品位的教师

陶行知先生说:“思想决定行动,行动养成习惯,习惯形成品质,品质决定命运”。最近从网上读了《影响教师一生的100个好习惯》一书,不禁对陶先生这句话有了更深刻的领悟和理解。阅读本书带给我的不仅是享受,更多的则是生活的引领,智慧的传递和方法的教授…

最傻的六种员工离职理由,希望你不是其中一员

最傻的六种员工离职理由,希望你不是其中一员

春节后,今年的中国员工离职率应该是最低的。但是职场上,还是会有很多员工提离职。离职原因各种各样, 不开心,不舒服,工资少,学不到东西等等。那么,最傻的六种员工离职是哪些呢?…