zoukankan      html  css  js  c++  java
  • (一)基本控件

    AndroidStudio环境搭建参考https://www.cnblogs.com/yanglh6-jyx/p/Android_AS_Configuration.html

    (一)环境基本开发操作

    开发环境基本操作如下:

    点击上图中的Text则进入文本编辑模式,如下图所示,其中id参数是唯一标记的,后续可通过此id获取到相关控件,如下图所示

    在java-com.example.app0下activity_main下进行逻辑代码编写如下所示:

    (二)Button控件

    button是开发过程中最基本的按键

            <Button
                android:id="@+id/btn_next"
                android:layout_width="150dp"
                android:text="下一张"
                android:layout_height="wrap_content" />

    (三)TextView

    文字显示控件

        <TextView
            android:id="@+id/tv_show"
            android:gravity="center"
            android:text="图片信息"
            android:textColor="@color/colorPrimary"
            android:layout_width="match_parent"
            android:layout_height="50dp" />

     (四)ImageView图片显示控件

        <ImageView
            android:id="@+id/iv_show"
            android:layout_width="match_parent"
            android:layout_height="393dp"
            android:layout_weight="1"
            android:background="@color/colorPrimaryDark" />

    //-------------------------------------------------------------------------基本代码-----------------------------------------------------------------------//

    <?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"
        tools:context=".MainActivity">
    
        <!--<TextView-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:text="Hello World!" />-->
    
        <!--<ImageView-->
            <!--android:src="@drawable/child"-->
            <!--android:layout_width="300dp"-->
            <!--android:layout_height="300dp" />-->
    
        <!--<Button-->
            <!--android:layout_width="200dp"-->
            <!--android:layout_height="50dp"-->
            <!--android:textColor="@color/colorPrimary"-->
            <!--android:text="按钮" />-->
        <ImageView
            android:id="@+id/iv_show"
            android:layout_width="match_parent"
            android:layout_height="393dp"
            android:layout_weight="1"
            android:background="@color/colorPrimaryDark" />
        
        <TextView
            android:id="@+id/tv_show"
            android:gravity="center"
            android:text="图片信息"
            android:textColor="@color/colorPrimary"
            android:layout_width="match_parent"
            android:layout_height="50dp" />
    
        <LinearLayout
            android:gravity="center"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <Button
                android:id="@+id/btn_previous"
                android:layout_width="150dp"
                android:text="上一张"
                android:layout_height="wrap_content" />
    
            <Button
                android:id="@+id/btn_next"
                android:layout_width="150dp"
                android:text="下一张"
                android:layout_height="wrap_content" />
    
        </LinearLayout>
    
    
    </LinearLayout>
    package com.example.app0;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
        ImageView imageView;
        TextView imageTitle;
        String[] titles;
        int[] images;
        int currentImage;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            initView();
    
            initData();
        }
    
        private void initData()
        {
            titles=new String[]{"第1张图片","第2张图片","第3张图片","第4张图片","第5张图片"};
            images=new int[]{R.drawable.child,R.drawable.child01,R.drawable.child02,R.drawable.child03,R.drawable.child04};
    
            imageView.setImageResource(images[0]);
            imageTitle.setText(titles[0]);
            currentImage=0;
        }
    
        private void initView()
        {
            imageView = findViewById(R.id.iv_show);
            imageTitle=findViewById(R.id.tv_show);
            Button prevBtn = findViewById(R.id.btn_previous);
            Button nextBtn=findViewById(R.id.btn_next);
    
            prevBtn.setOnClickListener(this);
            nextBtn.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v)
        {
            if(v.getId()==R.id.btn_next) {
                currentImage++;
    
                if(currentImage>4)
                    currentImage=0;
            }
            else {
                currentImage--;
    
                if(currentImage<0)
                    currentImage=4;
            }
    
            imageView.setImageResource(images[currentImage]);
            imageTitle.setText(titles[currentImage]);
        }
    }
  • 相关阅读:
    【已解决】Kettle新建数据库连接报错(Mysql,MS Sql Server)
    SQL面试题-练习2
    WIN7bat批处理遍历文件夹,输出当前文件夹下所有文件。
    【已解决】MYSQL安装过程报错,怎么解决?MySQL error 0: Authentication to host 'localhost' for user 'root' using method 'caching_sha2_password' failed with message: Reading from the stream has failed.
    常用外国在线英语词典-单词查询
    Oracle 11g 服务端的安装步骤
    Oracle 查询(SELECT)语句(一)
    Oracle 增删改(INSERT、DELETE、UPDATE)语句
    记录一个 C# 导出 Excel 的坑
    C# 中的浅拷贝与深拷贝
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/9913372.html
Copyright © 2011-2022 走看看