昨天學習完Textview的設置
今天來學視圖的基本大小對齊等
利用代碼設置視圖的寬高
import com.example.basiccontrols.util.Utils;
public class Acticity_View_Border extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_acticity_view_border);
        TextView tv_code = findViewById(R.id.tv_size);
        ViewGroup.LayoutParams params = tv_code.getLayoutParams();
        params.width = Utils.dip2px(this,300);
        tv_code.setLayoutParams(params);
    }
}
設置兩個視圖之間的間距
<?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="300dp"
    android:orientation="vertical"
    android:background="#00AAFF">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFF99"
        android:padding="60dp"
        android:layout_margin="20dp">
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF0000"/>
    </LinearLayout>
最後還有對齊的方式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#FFFF99"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:background="#ff0000"
        android:padding="10dp"
        android:layout_gravity="bottom"
        android:gravity="left|top">
        <View
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#00ffff">
        </View>
    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:background="#ff0000"
        android:padding="10dp"
        android:layout_gravity="top"
        android:gravity="right|bottom">
        <View
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#00ffff">
        </View>
    </LinearLayout>
</LinearLayout>
今天的東西開始要有美感了 完蛋zzz