说明:android循环控件,注册和显示内容
效果图:
step1: E:\projectgood\resget\demozz\IosDialogDemo-main\app\src\main\java\com\example\iosdialogdemo\TimerActivity.java
- package com.example.iosdialogdemo;
- import android.os.Bundle;
- import android.os.Handler;
- import android.widget.Button;
- import android.widget.TextView;
- import androidx.appcompat.app.AppCompatActivity;
- import java.util.Arrays;
- public class TimerActivity extends AppCompatActivity {
- private TextView tv_img0,tv_img1,tv_img2,tv_img3,tv_img4;
- private int[] tvIds = {R.id.tv_img0,R.id.tv_img1,R.id.tv_img2,R.id.tv_img3,R.id.tv_img4};
- private TextView[] tvGroups = {tv_img0,tv_img1,tv_img2,tv_img3,tv_img4};
- private int[] ages = {0,1,2,3,4};
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_same);
- for (int i=0;i<tvIds.length;i++){
- tvGroups[i] =findViewById(tvIds[i]);
- tvGroups[i].setText(String.valueOf(ages[i]));
- }
- }
- }
复制代码 step2: E:\projectgood\resget\demozz\IosDialogDemo-main\app\src\main\res\layout\activity_same.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal" android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@android:color/holo_blue_bright">
- <TextView
- android:id="@+id/tv_img0"
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:background="@android:color/holo_red_dark"
- android:textSize="50sp"
- />
- <TextView
- android:id="@+id/tv_img1"
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:background="@android:color/holo_orange_dark"
- android:textSize="50sp"
- />
- <TextView
- android:id="@+id/tv_img2"
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:background="@android:color/holo_blue_light"
- android:textSize="50sp"
- />
- <TextView
- android:id="@+id/tv_img3"
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:background="@android:color/holo_green_light"
- android:textSize="50sp"
- />
- <TextView
- android:id="@+id/tv_img4"
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:background="@android:color/holo_purple"
- android:textSize="50sp"
- />
- </LinearLayout>
复制代码 end
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |