跑马灯
TextView
<?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">
<!--学习的控件-->
<TextView
android:id="@+id/textview" (定位)
android:text="@string/TextView_1"(显示文字)
android:textColor="#FF635345"(文字颜色)
android:textStyle="italic"(文字风格)
android:textSize="30dp"(文字大小)
android:shadowColor="#ffff0000"(阴影颜色)
android:shadowRadius="3.0"(阴影模糊度)
android:shadowDx="5"(阴影x轴移动度)
android:shadowDy="5"(阴影y轴移动度)
android:background="#fff000"(背景颜色)
android:gravity="bottom"(文字位置)
android:layout_width="200dp"(控件宽度)
android:layout_height="200dp"(控件高度)
android:singleLine="true"(单行输出)
android:ellipsize="marquee"(省略模式)
android:marqueeRepeatLimit="marquee_forever"(字母动画播放次数)
android:focusable="true"(是否获得焦点)
android:focusableInTouchMode="true"(是否在触屏模式下获得焦点)>
<requestFocus/>
</TextView>
</LinearLayout>
buttom
<?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"
>
<Button
android:id="@+id/btn"
android:text="我是按钮"
android:background="@drawable/btn_image"
android:layout_width="200dp"
android:layout_height="100dp"/>
</LinearLayout>
java内容
package com.example.testbuttom;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "leo";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = findViewById(R.id.btn);
//点击监听
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//在TAG端口打印文字
Log.e(TAG, "onClick: ");
}
});
//长按监听
btn.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
Log.e(TAG, "onLongClick: ");
return false;
}
});
//触摸事件
btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.e(TAG, "onTouch: "+motionEvent.getAction());
return false;
}
});
}
}
edit_text:
<?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">
<EditText
android:drawableLeft="@drawable/ic_baseline_account_circle_24"
android:padding="30dp"
android:id="@+id/account"
android:layout_width="200dp"
android:layout_height="100dp"
android:inputType="date"
android:hint="请输入文字"/>
<EditText
android:id="@+id/password"
android:layout_width="202dp"
android:layout_height="100dp"
android:drawableLeft="@drawable/ic_baseline_android_24"
android:padding="30dp"
android:hint="请输入密码"
android:inputType="textPassword" />
<Button
android:id="@+id/btn_ok"
android:layout_width="200dp"
android:layout_height="100dp"
android:text="确定"/>
</LinearLayout>
java内容
package com.example.testedit;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "leo";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = findViewById(R.id.btn_ok);
EditText account = findViewById(R.id.account);
EditText password = findViewById(R.id.password);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = password.getText().toString();
Log.e(TAG, "onClick: "+text);
}
});
}
}
ImageView
<?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"
>
<ImageView
android:layout_width="wrap_content"(不能超过父组的容器宽度)
android:layout_height="wrap_content"(不能超过父组的容器高度)
android:maxHeight="200dp"(最宽200dp)
android:minHeight="500dp"(最高500dp)
android:adjustViewBounds="true"(允许根据图片调整)
android:background="@drawable/girl"
android:scaleType="center"(位置中心)/>
</LinearLayout>