Android布局截取

栏目: IOS · Android · 发布时间: 7年前

内容简介:执行逻辑

布局 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:ignore="ContentDescription,HardcodedText,UselessParent">

    <LinearLayout
        android:id="@+id/screenshotLayout"
        android:layout_width="310dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginEnd="25dp"
        android:layout_marginStart="25dp"
        android:layout_marginTop="25dp"
        android:background="@drawable/bg_qr_code"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginTop="17dp">

            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_centerVertical="true"
                android:src="@drawable/qq" />

            <TextView
                android:id="@+id/tv_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="10dp"
                android:layout_toEndOf="@id/iv_avatar"
                android:text="QQ"
                android:textColor="#000000"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/tv_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignStart="@id/tv_name"
                android:layout_below="@id/tv_name"
                android:text="好友"
                android:textColor="#9b9b9b"
                android:textSize="14sp" />
        </RelativeLayout>

        <ImageView
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="24dp"
            android:src="@drawable/generate" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="27dp"
            android:layout_marginTop="23dp"
            android:text="扫一扫加为好友"
            android:textColor="#6c6b6e"
            android:textSize="12sp"
            tools:ignore="HardcodedText" />
    </LinearLayout>
</FrameLayout>

执行逻辑

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        screenshotLayout.setOnClickListener { screenShot() }
    }

    private fun screenShot() {
        screenshotLayout.isDrawingCacheEnabled = true
        val bitmap = screenshotLayout.getDrawingCache(false)
        screenshotLayout.destroyDrawingCache()
        bitmap.toString() // Bitmap to save.
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

响应式Web设计实践

响应式Web设计实践

[美] Tim Kadlec / 侯鸿儒 / 人民邮电出版社 / 2013-3-1 / 55.00元

随着各种各样的移动设备不断地涌现到使用者面前,Web设计的适应性已经成为设计师们所面临的最为艰巨的挑战。你设计出的网站不仅要在桌面计算机的大尺寸屏幕上可以为用户提供友好的UI和用户体验,同时在小尺寸屏幕上也应该可以提供一致的用户体验,并可以让用户能够在桌面大屏幕上和移动小屏幕上平滑切换,同时没有任何的不适应感觉。 本书作者是一位出色的开发者,在本书中,他将诸多技术和设计理念杂糅在一起,再辅以......一起来看看 《响应式Web设计实践》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具