androidstudio简单页面设计

一、代码设计

(一)主页面

1.ThreeActivity

package com.example.helloworld1;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.example.helloworld.R;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ThreeActivity extends AppCompatActivity  {
    private ImageButton bnt_mail;
    private ImageButton bnt_phone;
    private ImageButton bnt_carmera;
    private ImageButton bnt_relation;
    EditText phonenum1;
    EditText phonenum2;
    ImageView image;

    public static final int TAKE_PHOTO = 2;//声明一个请求码,用于识别返回的结果
    private ImageView picture;
    private Uri imageUri;
    private final String filePath = Environment.getExternalStorageDirectory() + File.separator + "output_image.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_three);
        bnt_mail = findViewById(R.id.bnt_mail1);
        bnt_mail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(ThreeActivity.this,MailActivity.class);
                startActivity(intent);
            }
        });
        bnt_phone = findViewById(R.id.bnt_phone1);
        bnt_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(ThreeActivity.this,PhoneActivity.class);
                startActivity(intent);
            }
        });
        bnt_relation = findViewById(R.id.bnt_relation1);
        bnt_relation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(ThreeActivity.this,RelationActivity.class);
                startActivityForResult(intent,0);
            }
        });
        bnt_relation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(ThreeActivity.this,RelationActivity.class);
                startActivityForResult(intent,1);
            }
        });
        phonenum1 = findViewById(R.id.phoneNum);
        phonenum2 = findViewById(R.id.phoneNum);
        picture = findViewById(R.id.pictureshow);
        bnt_carmera = findViewById(R.id.carmera1);
        image=findViewById(R.id.pictureshow);
        bnt_carmera.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent it = new Intent();
              it.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
              startActivityForResult(it,4);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) return;
        Bundle bundle = data.getExtras();
        if (requestCode == 0) {
            String phoneNum = bundle.getString("phonenum");
            phonenum1.setText(phoneNum);
        } else if (requestCode == 1) {
            String phoneNum = bundle.getString("phonenum");
            phonenum2.setText(phoneNum);
        }
       else if(requestCode==4)
        {
            Bitmap b=(Bitmap) bundle.get("data");
            image.setImageBitmap(b);

        }


        }


        }



在这里插入图片描述

2,activity_three.xml

<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingBottom="20dp"
    android:paddingTop="20dp"
    android:columnCount="3"
    android:rowCount="8"
    android:orientation="horizontal"
    tools:context="com.example.helloworld1.ThreeActivity">

    <ImageButton
        android:id="@+id/bnt_mail1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_row="0"
        android:layout_rowSpan="1"
        android:layout_column="0"
        android:layout_columnSpan="1"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@mipmap/mail"
        android:text="短信" />

    <ImageButton
        android:id="@+id/bnt_phone1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_row="0"
        android:layout_rowSpan="1"
        android:layout_column="1"
        android:layout_columnSpan="1"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@mipmap/phone"
        android:text="电话" />

    <ImageButton
        android:layout_row="0"
        android:id="@+id/carmera1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_rowSpan="1"
        android:layout_columnSpan="1"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="15dp"
        android:background="@mipmap/carmera"
        android:text="照相" />

    <EditText

        android:id="@+id/phoneNum"
        android:layout_row="2"
        android:layout_columnSpan="2"
        android:layout_column="0"
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:hint="输入电话号码"
        android:inputType="number" />
    <ImageButton

        android:layout_row="2"
        android:layout_rowSpan="1"
        android:layout_columnSpan="1"
        android:text="联系人"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@mipmap/realate"
        android:id="@+id/bnt_relation1"/>
    <ImageView
        android:layout_row="2"
        android:layout_rowSpan="4"
        android:layout_columnSpan="3"
        android:id="@+id/pictureshow"
        android:layout_width="380dp"
        android:layout_height="380dp"
        android:layout_gravity="center_horizontal"
        />

</GridLayout>

在这里插入图片描述

(二)联系人电话

1.RelationActivity

package com.example.helloworld1;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.example.helloworld.R;

import java.nio.charset.StandardCharsets;

public class RelationActivity extends AppCompatActivity  {
    TextView relationphone1;
    TextView relationphone2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_relation);
        relationphone1=findViewById(R.id.relationphone1);
        relationphone2=findViewById(R.id.relationphone2);
        relationphone1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
               String phonenum3=relationphone1.getText().toString();
                intent.putExtra("phonenum",phonenum3);
                setResult(0,intent);
                finish();

            }
        });
        relationphone2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                String phonenum3=relationphone2.getText().toString();
                intent.putExtra("phonenum",phonenum3);
                setResult(1,intent);
                finish();
            }
        });
   }}


在这里插入图片描述
2.activity_three.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:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingBottom="20dp"
    android:paddingTop="20dp"
    android:orientation="vertical"
    tools:context="com.example.helloworld1.RelationActivity">
    <TextView
        android:id="@+id/relationphone1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1124422242"
        />
    <TextView

        android:id="@+id/relationphone2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1543666582" />
</LinearLayout>

在这里插入图片描述

二、演示界面

1.点击简单页面进入
在这里插入图片描述

在这里插入图片描述
2.点击短信图标跳转
在这里插入图片描述
3.点击电话图标跳转
在这里插入图片描述
3.点击相机图标跳转拍照后
返回相片
在这里插入图片描述
4.点击联系人图标跳转到另一个页面
在这里插入图片描述
点击号码返回值
在这里插入图片描述

  • 4
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio设计商品页面可以通过以下步骤完成: 1. 创建一个新的Activity或Fragment用于显示商品页面。在Project视图中,右键点击Java文件夹,选择"New" -> "Activity"或"Fragment"来创建一个新的页面。 2. 在布局文件中设计商品页面的UI。在res/layout目录下找到对应的布局文件,通常是activity_main.xml或fragment_main.xml。在这个文件中,你可以使用各种布局和视图组件来设计商品页面的外观。 3. 添加商品图片。在布局文件中,你可以使用ImageView组件来显示商品的图片。通过设置ImageView的src属性来指定图片资源,或者使用网络库加载网络图片。 4. 显示商品信息。利用TextView组件来显示商品名称、价格、描述等信息。通过在布局文件中设置TextView的text属性或者在代码中动态设置TextView的文本内容。 5. 设计购买按钮或其他交互组件。根据你的需求,可以在布局文件中添加Button或其他视图组件来处理购买商品、添加到购物车等操作。 6. 添加商品数据。你可以在代码中创建一个数据模型类来表示商品信息,然后在Activity或Fragment中将商品数据加载到UI控件中。例如,你可以创建一个Product类来保存商品信息,然后在页面中实例化Product对象并将其属性赋值给相应的视图组件。 7. 处理商品点击事件或其他用户交互。如果用户点击购买按钮或其他交互组件,你可以在代码中实现相应的逻辑,比如弹出对话框确认购买、跳转到支付页面等。 这些步骤可以帮助你在Android Studio设计和实现一个简单的商品页面。根据你的需求,还可以进一步定制和扩展页面的功能和样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值