Android --- 常用控件的用法 ImageView EditView

mac2024-07-21  66

 

目录

基础板块

设置文字标记:

显示Intent

控件

垂直滚动条、水平滚动条

ImageView 

利用Glide获得网络资源

 EditView

判断输入框内是否为空

 

 


基础板块

文字居中:  android:gravity="center"行间距:     android:lineSpacingExtra     Space:间距,空格    Extra:额外的显示方向: android:orientation="vertical"    orientation:方向   Horizontal:水平    Vertical:垂直  AndroidManifest.xml: <activity android:name=".FirstActivity" //指定具体注册活动 android:label="This is FirstActivity" > //标题栏内容 <intent-filter> <action android:name="android.intent.action.MAIN" /> //表明此为主活动 <category android:name="android.intent.category.LAUNCHER" /> //表明此为主活动 </intent-filter> </activity>

 

 

设置文字标记:

text.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//添加下划线

private Button bt1;                            //声明按钮     

       bt1 = findViewById(R.id.tvbt);          //通过id找到activity中的按钮

显示Intent

Intent intent = new Intent(FirstActivity.this, SecondActivity.class); startActivity(intent);

 

控件

垂直滚动条、水平滚动条

<HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" />

 

ImageView 

android:scaleType="fitXY"                     //缩放

fitXY XY轴拉伸 centerCrop 比例放大并剪裁 fitEnd 贴底边开始放

利用Glide获得网络资源

 AndroidMainifest.xml     赋予Internet许可 <uses-permission android:name="android.permission.INTERNET" /> build.gradle    配置 repositories { mavenCentral() google() } dependencies {   implementation 'com.github.bumptech.glide:glide:4.10.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0' } ImgView.java    方法 Glide.with(this).load("https://i2.hdslb.com/bfs/archive/bd5837c3754ebf8a352ba978383445d785d3643d.png@336w_190h.webp").into(img_2); //给this(ImgView)Activity加载来自“url”的资源,,赋予给img_2控件

 EditView

判断输入框内是否为空

TextUtils.isEmpty(edit.getText()) 输入框为     空------------TRUE 非空-----------FALSE //EXEC控件点击事件, //若输入框为空,toast:参数错误 //不为空,传参数并跳转到目的页面 exec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(edit.getText())) { rows = Integer.parseInt(edit.getText().toString()); if (rows >= 1) { Intent intent = new Intent(AdaptActivity.this, AdaptShow.class); intent.putExtra("row1", rows); startActivity(intent); Toast.makeText(AdaptActivity.this, "到达目标页面", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(AdaptActivity.this, "参数错误", Toast.LENGTH_SHORT).show(); } } });

 

 

最新回复(0)