首页 > 其他分享 >Android Studio布局一

Android Studio布局一

时间:2023-02-26 16:23:23浏览次数:35  
标签:layout 布局 height width 200dp Studio background Android android

 

一:纵向布局
<?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:background="@color/black"
android:layout_width="200dp"
android:layout_height="200dp"/>
<ImageView
android:background="#FF0000"
android:layout_width="200dp"
android:layout_height="200dp"/>
<ImageView
android:background="#00FFFF"
android:layout_width="200dp"
android:layout_height="200dp"
</LinearLayout>
结果演示:

二:横向布局

<?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="horizontal">//横向布局(默认)
<ImageView
android:background="@color/black"
android:layout_width="100dp"
android:layout_height="200dp"/>
<ImageView
android:background="#FF0000"
android:layout_width="100dp"
android:layout_height="200dp"/>
<ImageView
android:background="#00FFFF"
android:layout_width="100dp"
android:layout_height="200dp"/>
</LinearLayout>
结果:

 


 三:对齐方式

父类对齐:
<?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:gravity="center_horizontal|bottom"//对齐方式,多个组合
android:orientation="horizontal">
<ImageView
android:background="@color/black"
android:layout_width="100dp"
android:layout_height="200dp"/>
<ImageView
android:background="#FF0000"
android:layout_width="100dp"
android:layout_height="200dp"/>
<ImageView
android:background="#00FFFF"
android:layout_width="100dp"
android:layout_height="200dp"/>
</LinearLayout>
结果演示:

 


子类对齐:

未添加前:

添加: android:layout_gravity="center_horizontal"/>

<?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:background="@color/black"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>
<ImageView
android:background="#FF0000"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>

<ImageView
android:background="#00FFFF"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>

</LinearLayout>

 

进行修改后:

 

 

 

 

 

四:分割线

 第一种方法:

<?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:divider="@drawable/divider"//分割线
android:showDividers="middle"//分割位置
android:dividerPadding="100dp"
android:orientation="vertical">
<ImageView
android:background="@color/black"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>
<ImageView
android:background="#FF0000"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>

<ImageView
android:background="#00FFFF"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
结果:
第二种方法:绘制
<View
android:background="@color/purple_500"
android:layout_width="wrap_content"
android:layout_height="10dp"/>
结果:

五:权重(按比例分配剩余空间,无剩余则无法分配)

 

<?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:dividerPadding="100dp"
android:orientation="vertical">
<ImageView
android:background="@color/black"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_weight="1"//剩余空间全部给(因为一)
android:layout_gravity="center_horizontal"/>
<ImageView
android:background="#FF0000"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>

<ImageView
android:background="#00FFFF"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>

 

注意:match_parent的相关操作。

 

 



 

 

 


 




 

 

 

标签:layout,布局,height,width,200dp,Studio,background,Android,android
From: https://www.cnblogs.com/JIANGzihao0222/p/17154919.html

相关文章

  • Android Studio Button
    本次Button内容我认为比较重要首先对于Button属性来说他是TextView的子类继承于TextView但是比起TextView它增加了两个属性1.textAllCaps是否将英文字母转为大写,true......
  • Android Studio GridLayout & ScrollView
    GridLayout是网格布局感觉在设计表格的时候会有一些用处知识点只有两个 columnCount属性,指定了网格的列数,即每行放多少个rowCount属性,指定行数,即每行放多少个要注意......
  • Deleaker is ready for Visual Studio 2022!
    DeleakerisreadyforVisualStudio2022!On November3,2021 By ArtemRazin In UncategorizedSinceMicrosoftannouncedthefirstpreviewofVisualStudi......
  • Android Studio LinearLayout & RelativeLayout
    1、LinearLayout线性布局主要分为两部分内容第一部分是进行线性布局的方向设置即水平方向和竖直方向用orientation属性值进行设置当它为horizontal的时候表示水平方......
  • springboot3.0整合GraalVM-Native-Support,打包本地exe(native-image)。添加native-maven
    0.【idea新建一个springbootdemo项目】勾选GraalVMNativeSupport。其它略(太基础了)1.【环境准备】安装GraalVM、VisualStudio、NativeImage​​https://gitee.com/lishu......
  • Android Studio 视图对齐方式
    这里有两种类型的对齐1、layout_gravity用于当前视图相对于上级视图的对齐方式2、gravity用于下级视图相对于当前视图的对齐方式具体如下代码和图<?xmlversion="1.......
  • Audroid studio_EditText
    今天再次学了一遍button事件,发现可能由于版本问题,视频教程与实际操作有出入,暂时不做对button的总结. EditText:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutx......
  • 解决在Android studio的Button控件下background背景设置不起作用的问题
    Button控件默认的背景是深紫色的,有时候会看不清按钮上的文本,显得很不方便,想要修改背景色所以添加了background字段,但是又不起作用!!!1.找到values文件夹下面的themes文件夹,打......
  • android的基本控件TextView
    作用TextView(文本框),用于显示文本的一个控件属性详解<TextView android:id="@+id/txtOne"android:layout_width="wrap_content"android:layout_heigh......
  • Android-实现增加数据进入数据库
    继续写简单增删改查,终于可以实现插入数据进入数据库了主要代码差不多了,现在主要是需要解决一个显示数据的问题,这个问题之后接着写。初步效果  然后我们用可视化应用......