安卓开发学习之002 LinearLayout之android:layout_gravity详解

本文详细介绍了Android中layout_gravity属性的使用方法及效果展示,包括不同属性值的意义、特殊情况下的表现,以及与gravity属性的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.使用说明

这个是针对控件本身而言,用来控制该控件在包含该控件的父控件中的位置。同样,当我们在Button按钮控件中设置android:layout_gravity=”left”属性时,表示该Button按钮将位于界面的左部。

2.属性值

这两个属性可选的值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。
一个属性可以包含多个值,需用“|”分开。其含义如下:

属性值含义
top将对象放在其容器的顶部,不改变其大小.
bottom将对象放在其容器的底部,不改变其大小.
left将对象放在其容器的左侧,不改变其大小.
right将对象放在其容器的右侧,不改变其大小.
center_vertical将对象纵向居中,不改变其大小.
垂直对齐方式:垂直方向上居中对齐。
fill_vertical必要的时候增加对象的纵向大小,以完全充满其容器.
垂直方向填充
center_horizontal将对象横向居中,不改变其大小.
水平对齐方式:水平方向上居中对齐
fill_horizontal必要的时候增加对象的横向大小,以完全充满其容器.水平方向填充
center将对象横纵居中,不改变其大小.
fill必要的时候增加对象的横纵向大小,以完全充满其容器.
clip_vertical附加选项,用于按照容器的边来剪切对象的顶部和/或底部的内容. 剪切基于其纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部.
垂直方向裁剪
clip_horizontal附加选项,用于按照容器的边来剪切对象的左侧和/或右侧的内容. 剪切基于其横向对齐设置:左侧对齐时,剪切右侧;右侧对齐时剪切左侧;除此之外剪切左侧和右侧.
水平方向裁剪

3.我们来看一下效果图

这里写图片描述
这里写图片描述

4.布局文件

布局文件为res/layout/fragment_layout_gravity.xml

<?xml version="1.0" encoding="utf-8"?>
<!--当我们采用LinearLayout布局时,有以下特殊情况需要我们注意:
(1)当 android:orientation="vertical"  时, android:layout_gravity只有水平方向的设置才起作用,
    垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
(2)当 android:orientation="horizontal" 时, android:layout_gravity只有垂直方向的设置才起作用,
    水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:orientation="horizontal">
            <!-- 靠上对齐 将对象推至其所在容器的顶端而不改变其尺寸-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:text="top"/>
            <!-- 靠下对齐-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:text="bottom"/>
            <!-- 垂直居中-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:text="cen_ver"/>
            <!-- 有需要时将沿垂直方向填满容器-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="fill_vertical"
                android:text="fill_ver"
                />

            <!--clip_vertical 垂直方向裁剪 当对象边缘超出容器的时候,将上下边缘超出的部分剪切掉,剪切基于纵向对齐设置:
            默认剪切底部
            注意此属性要在父容器中设置,并且子视图高度比父视图高度高-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="top|clip_vertical"
                >
                <!-- 剪切底部-->
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="60dp"
                    android:text="top|clip_ver"/>
            </LinearLayout>

            <!--注意,不同于在gravity中属性,这里bottom只是表明控件位于底部,clip_horizontal 仍然是默认剪切底部
            如果需要剪切上部,则添加属性android:gravity="bottom|clip_vertical"-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="bottom|clip_vertical"
                >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="60dp"
                    android:text="bot|clip_ver"/>
            </LinearLayout>
            <!--剪切上部-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="bottom|clip_vertical"
                android:gravity="bottom|clip_vertical"
                >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="60dp"
                    android:text="bot|clip_ver"/>
            </LinearLayout>
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="#f00"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <!-- 默认值 控件左对齐,文字居中对齐-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="default"
                />


            <!-- 靠右对齐-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:text=" مرحبا right"/>

            <!-- 靠左对齐-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:text=" مرحبا left"/>

            <!-- 基于阅读顺序的开始位置对齐
            如果时从左到右的语言文字(中英文),那么start就等同于left
            如果时从右到左的语言文字(阿拉伯语),那么start就等同于right
            可在布局预览界面 选择preview Right-To-Left 产看效果
            -->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:text="مرحباstart"/>

            <!-- 基于阅读顺序的结束位置对齐
           如果时从左到右的语言文字(中英文),那么end就等同于right
           如果时从右到左的语言文字(阿拉伯语),那么end就等同于left
           可在布局预览界面 选择preview Right-To-Left 产看效果
           -->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:text="مرحباend"/>


            <!-- 水平居中-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="center_horizontal"/>

            <!-- 垂直加水平方向居中 效果等同于center_vertical|center_horizontal-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="center"/>


            <!-- 有需要时将沿水平方向填满容器-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="fill_horizontal"
                android:text="fill_horizontal"/>

            <!-- 有需要时将沿水平方向和垂直方向填满容器-->
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="fill"
                android:text="fill"/>


            <!--clip_horizontal 水平方向裁剪 当对象边缘超出容器的时候,将左右边缘超出的部分剪切掉,剪切基于横向对齐设置:
            默认剪切右部
            注意此属性要在父容器中设置,并且子视图宽度比父视图宽度大-->
            <LinearLayout
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_gravity="left|clip_horizontal"
                >
                <!--剪切右部-->
                <Button
                    android:layout_width="200dp"
                    android:layout_height="match_parent"
                    android:text="left|clip_horizontal"/>
            </LinearLayout>


            <!--注意,不同于在gravity中,这里right只是表明控件位于右部,clip_horizontal 仍然是默认剪切右部
            如果需要剪切右部,则添加属性android:gravity="right|clip_horizontal"-->
            <LinearLayout
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:layout_gravity="right|clip_horizontal"
                >

                <Button
                    android:layout_width="250dp"
                    android:layout_height="match_parent"
                    android:text="right|clip_horizontal"/>
            </LinearLayout>
            <!--剪切右部-->
            <LinearLayout
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:layout_gravity="right|clip_horizontal"
                android:gravity="right|clip_horizontal"
                >

                <Button
                    android:layout_width="250dp"
                    android:layout_height="match_parent"
                    android:text="right|clip_horizontal"/>
            </LinearLayout>

        </LinearLayout>
    </LinearLayout>
</ScrollView>

5. layout_gravity有时候设置不起作用?

当我们采用LinearLayout布局时,有以下特殊情况需要我们注意:
(1)当 android:orientation=”vertical” 时, android:layout_gravity只有水平方向的设置才起作用,
垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
(2)当 android:orientation=”horizontal” 时, android:layout_gravity只有垂直方向的设置才起作用,
水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。

6.android:gravity 与android:layout_gravity区别总结

android:gravity:
这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置

android:layout_gravity:
这个是针对控件本身而言,用来控制该控件在包含该控件的父控件中的位置

开发工具:Android Studio1.4
SDK: Android 6.0
API 23

代码下载:Layout_Gravity.zip

MainActivity:package com.videogo.ui.login; import android.content.res.Configuration; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import com.videogo.exception.BaseException; import com.videogo.exception.ErrorCode; import com.videogo.openapi.EZConstants; import com.videogo.openapi.EZOpenSDK; import com.videogo.openapi.EZPlayer; import ezviz.ezopensdk.R; public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback, Handler.Callback { private static final String TAG = "EZPreview"; private static final int MSG_VIDEO_SIZE_CHANGED = 1; private static final int MSG_REALPLAY_PLAY_SUCCESS = 2001; private static final int MSG_REALPLAY_PLAY_FAIL = 2002; // 接收的参数键 private static final String KEY_APPKEY = "appkey"; private static final String KEY_SERIAL = "serial"; private static final String KEY_VERIFYCODE = "VerifyCode"; private static final String KEY_ACCESSTOKEN = "accessToken"; private static final String KEY_CAMERANO = "cameraNo"; private EZPlayer mEZPlayer; private SurfaceView mSurfaceView; private SurfaceHolder mSurfaceHolder; // 从Intent中获取的参数 private String mAppKey; private String mDeviceSerial; private String mVerifyCode; private String mAccessToken; private int mCameraNo = 0; // 默认通道号0 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activitymain); // 1. 从Intent中获取参数 extractParametersFromIntent(); // 2. 初始化UI initUI(); // 3. 初始化SDK并创建播放器 initSDKAndCreatePlayer(); } /** * 从Intent中提取传递的参数 */ private void extractParametersFromIntent() { Bundle extras = getIntent().getExtras(); if (extras != null) { mAppKey = extras.getString(KEY_APPKEY, ""); mDeviceSerial = extras.getString(KEY_SERIAL, ""); mVerifyCode = extras.getString(KEY_VERIFYCODE, ""); mAccessToken = extras.getString(KEY_ACCESSTOKEN, ""); mCameraNo = extras.getInt(KEY_CAMERANO, 0); Log.d(TAG, "Received parameters:"); Log.d(TAG, "AppKey: " + mAppKey); Log.d(TAG, "DeviceSerial: " + mDeviceSerial); Log.d(TAG, "VerifyCode: " + mVerifyCode); Log.d(TAG, "AccessToken: " + mAccessToken); Log.d(TAG, "CameraNo: " + mCameraNo); } else { Log.e(TAG, "No parameters received from intent"); // 如果没有参数,可以显示错误信息并退出 finish(); } } /** * 初始化UI组件 */ private void initUI() { mSurfaceView = findViewById(R.id.realplay_sv); if (mSurfaceView != null) { mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.addCallback(this); } else { Log.e(TAG, "SurfaceView not found with ID realplay_sv"); } } /** * 初始化SDK并创建播放器 */ private void initSDKAndCreatePlayer() { try { // 1. 初始化SDK EZOpenSDK.initLib(getApplication(), mAppKey); EZOpenSDK.getInstance().setAccessToken(mAccessToken); // 2. 创建播放器 createPlayer(); } catch (Exception e) { Log.e(TAG, "SDK initialization failed", e); } } /** * 创建播放器并开始播放 */ private void createPlayer() { try { // 1. 创建播放器实例 mEZPlayer = EZOpenSDK.getInstance().createPlayer(mDeviceSerial, mCameraNo); // 2. 配置播放器 mEZPlayer.setHandler(new Handler(this)); if (mSurfaceHolder != null) { mEZPlayer.setSurfaceHold(mSurfaceHolder); } if (mVerifyCode != null && !mVerifyCode.isEmpty()) { mEZPlayer.setPlayVerifyCode(mVerifyCode); } // 3. 开始播放 mEZPlayer.startRealPlay(); } catch (Exception e) { Log.e(TAG, "Player creation failed", e); } } // 处理屏幕旋转按钮点击 public void changeScreen(View view) { Log.d(TAG, "Change screen orientation requested"); // 实际切换屏幕方向的代码 int currentOrientation = getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } // Surface回调接口实现 @Override public void surfaceCreated(@NonNull SurfaceHolder holder) { if (mEZPlayer != null) { mEZPlayer.setSurfaceHold(holder); } } @Override public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {} @Override public void surfaceDestroyed(@NonNull SurfaceHolder holder) { if (mEZPlayer != null) { mEZPlayer.setSurfaceHold(null); } } @Override protected void onStop() { super.onStop(); if (mEZPlayer != null) { mEZPlayer.stopRealPlay(); } } @Override protected void onDestroy() { super.onDestroy(); if (mEZPlayer != null) { mEZPlayer.release(); mEZPlayer = null; } } // Handler回调处理播放状态 @Override public boolean handleMessage(@NonNull Message msg) { Log.d(TAG, "handleMessage: " + msg.what); switch (msg.what) { case MSG_VIDEO_SIZE_CHANGED: // 视频尺寸变化,可以调整SurfaceView的布局 break; case MSG_REALPLAY_PLAY_SUCCESS: Log.i(TAG, "播放成功"); break; case MSG_REALPLAY_PLAY_FAIL: Log.e(TAG, "播放失败"); BaseException error = (BaseException) msg.obj; int errorCode = error.getErrorCode(); if (errorCode == ErrorCode.ERROR_INNER_VERIFYCODE_NEED || errorCode == ErrorCode.ERROR_INNER_VERIFYCODE_ERROR) { // 处理验证码错误 // 这里应该提示用户输入验证码,然后重新设置并播放 // 示例中暂时保留模拟输入验证码 mVerifyCode = "123456"; if (mEZPlayer != null) { mEZPlayer.setPlayVerifyCode(mVerifyCode); mEZPlayer.startRealPlay(); } } else { Log.e(TAG, "播放失败,错误码: " + errorCode); } break; } return true; } } activity.xml:<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff2f2f2" tools:context="com.videogo.ui.login.MainActivity"> <RelativeLayout android:id="@+id/ra_title" android:layout_width="match_parent" android:layout_height="44dp" android:background="@mipmap/title_bg"> <TextView android:id="@+id/titlename" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_gravity="center" android:text="易丰视频监控" android:textColor="@android:color/white" android:textSize="18sp" /> <ImageButton android:id="@+id/back" android:layout_width="40dp" android:layout_height="match_parent" android:background="@null" android:contentDescription="@null" android:paddingLeft="10dp" android:src="@mipmap/img_back" /> <ImageButton android:id="@+id/ib_rotate" android:layout_width="50dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:contentDescription="@null" android:onClick="changeScreen" android:layout_marginRight="6dp" android:scaleType="centerInside" android:background="@drawable/gps_select" android:src="@mipmap/ic_size_sel" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl_control" android:layout_width="match_parent" android:layout_height="266dp" android:layout_alignParentBottom="true" > <LinearLayout android:id="@+id/ll_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerInParent="true" android:background="@mipmap/ycjk_yp" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb1" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb2" /> <ImageButton android:visibility="gone" android:id="@+id/left_up" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb3" /> </LinearLayout> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb4" /> </LinearLayout> <ImageButton android:id="@+id/ptz_top_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/nnew_video_up" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb1" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb3" /> <ImageButton android:visibility="gone" android:id="@+id/right_up" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb2" /> </LinearLayout> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb4" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" > <ImageButton android:id="@+id/ptz_left_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/nnew_video_left" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_zj" /> <ImageButton android:id="@+id/ptz_right_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/nnew_video_right" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb4" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb2" /> <ImageButton android:visibility="gone" android:id="@+id/left_down" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb3" /> </LinearLayout> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb1" /> </LinearLayout> <ImageButton android:id="@+id/ptz_bottom_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/nnew_video_down" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb4" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb3" /> <ImageButton android:visibility="gone" android:id="@+id/right_down" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb2" /> </LinearLayout> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ycjk_kb1" /> </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@id/ll_center" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageButton android:id="@+id/focus_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="16dp" android:text="焦距 +" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/guangquan_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more3" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="光圈 +" android:textSize="16dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/zoom_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more5" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="变倍 +" android:textSize="16dp" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/ll_center" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/foucus_reduce" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more2" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="焦距 -" android:textSize="16dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/guangquan_reduce" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more4" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="光圈 -" android:textSize="16dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/zoom_reduce" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more6" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="变倍 -" android:textSize="16dp" /> </LinearLayout> </LinearLayout> </RelativeLayout> <RelativeLayout android:layout_above="@id/rl_control" android:layout_below="@id/ra_title" android:layout_width="match_parent" android:layout_height="match_parent" > <SurfaceView android:id="@+id/realplay_sv" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" /> <ImageButton android:id="@+id/ib_rotate2" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentLeft="true" android:layout_marginLeft="3dp" android:background="@color/green" android:contentDescription="@null" android:onClick="changeScreen" android:src="@mipmap/img_systems_close" /> <ProgressBar android:id="@+id/liveProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <LinearLayout android:id="@+id/ll_hc" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" > <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:layout_weight="1" > <ImageButton android:id="@+id/ptz_top_btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/h_up" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:layout_weight="1" > <ImageButton android:id="@+id/ptz_bottom_btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/h_down" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:layout_weight="1" > <ImageButton android:id="@+id/ptz_left_btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/h_left" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:layout_weight="1" > <ImageButton android:id="@+id/ptz_right_btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/h_right" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:layout_weight="1" > <ImageButton android:id="@+id/focus_add2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more1" /> </LinearLayout> <LinearLayout android:gravity="center" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" > <ImageButton android:id="@+id/foucus_reduce2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more2" /> </LinearLayout> <LinearLayout android:gravity="center" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" > <ImageButton android:id="@+id/zoom_add2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more5" /> </LinearLayout> <LinearLayout android:gravity="center" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" > <ImageButton android:id="@+id/zoom_reduce2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/video_more6" /> </LinearLayout> </LinearLayout> </RelativeLayout> </RelativeLayout> 在上述代码中设置当直播画面realplay_sv在开始播放的时候隐藏就android:id="@+id/liveProgressBar"这个加载图标,当手机是竖屏的时候隐藏android:id="@+id/ll_hc"这一模块中的8个按钮以及android:id="@+id/ib_rotate2"这一个按钮,其他正常显示。当手机是横屏的时候隐藏android:id="@+id/rl_control"这一模块所有布局,其他正常显示。
06-24
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" tools:context=".MainActivity"> <ImageView android:layout_width="match_parent" android:layout_height="85dp" android:src="@drawable/login" android:layout_marginTop="80dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="MyMUSIC" android:layout_marginTop="20dp" android:textColor="#E62C21" android:gravity="center|center_vertical|center_horizontal" android:layout_marginBottom="65dp" android:textSize="25sp" android:textStyle="bold" /> <EditText android:id="@+id/login_account" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#B3FFFFFF" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" android:layout_marginTop="10dp" android:hint="请输入账号" android:textSize="25sp" android:textStyle="bold" android:textColorHint="#FFFFFF" android:background="@drawable/edit_login_bg" android:padding="10dp" android:drawablePadding="10dp" android:drawableLeft="@drawable/icon_login" /> <EditText android:id="@+id/login_pwd" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#B3FFFFFF" android:layout_marginTop="20dp" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" android:hint="请输入密码" android:textSize="25sp" android:textStyle="bold" android:textColorHint="#FFFFFF" android:background="@drawable/edit_login_bg" android:padding="10dp" android:drawablePadding="10dp" android:drawableLeft="@drawable/icon_pass" android:inputType="textPassword" /> <LinearLayout android:gravity="center_horizontal|center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp" android:layout_marginLeft="50dp" android:layout_marginRight="50dp"> <Button android:id="@+id/login_denglu_btn" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="登录" android:layout_marginRight="20dp" android:background="@drawable/button_login_bg" android:textColor="#FDFDFD" android:foreground="?android:attr/selectableItemBackground" /> <Button android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="注册" android:layout_marginLeft="20dp" android:background="@drawable/button_login_bg" android:textColor="#FDFDFD" android:foreground="?android:attr/selectableItemBackground" />
03-16
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值