【问题标题】:Layout screen shot with gridview使用 gridview 布局屏幕截图
【发布时间】:2013-08-29 09:08:05
【问题描述】:
<LinearLayout
        android:id="@+id/screenshotlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:layout_weight="4"
        android:orientation="vertical" >

        <GridView
            android:id="@+id/gridview"
            android:background="#ffffff"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:columnWidth="320dp"
            android:gravity="center"
            android:numColumns="1"
            android:verticalSpacing="5dp" />

        <TextView
            android:id="@+id/editText3"
            android:background="@color/DarkGrey"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:gravity="bottom"
            android:text="TextView LinearLayout"
            android:textSize="20dp"
            android:textStyle="bold" >

            <requestFocus />
        </TextView>

    </LinearLayout>

这是我的布局。 Gridview 的工作方式类似于垂直滚动条。我正在向该 Gridview 动态添加位图。网格大小可能会有所不同。

【问题讨论】:

    标签: android gridview textview screenshot


    【解决方案1】:

    您可以通过以下方式获取布局的位图屏幕截图:

    1. 为您的布局添加一个 ID(我的称为“屏幕”):
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/screen"
       android:layout_width="match_parent"
       android:layout_height="match_parent" >
    
       <!--//add your buttons, texts, other layouts, etc here-->
    
    </LinearLayout>
    
    1. 您可以通过以下方式以编程方式捕获屏幕截图:

    查看屏幕 = 屏幕 = (View) findViewById(R.id.screen);
    查看 rootview = screen.getRootView();
    rootview.setDrawingCacheEnabled(true);

    位图位图 = rootview.getDrawingCache();

    这对我有用。您可以在 ImageView 上使用 .setImageBitmap(bitmap) 方法来显示屏幕截图。

    【讨论】:

    • 嗨,Harith 感谢您的回复 :-)。正如我所提到的,我可以拍摄布局或滚动视图和网格视图的屏幕截图。在我的应用程序中,我想用gridview下方的textview截取gridview的屏幕截图。 Gridview 像垂直滚动视图一样工作。我不能将 textview 放入 Gridview 广告 gridview 是一个小部件。
    • 我很确定,如果您的 GridView 和 TextView 在 LinearLayout 内,您可以向 LinearLayout 添加一个 ID,然后使用 LinearLayout 的 ID 对 GridView 和 TextView 进行屏幕截图。跨度>
    • 线性布局的高度是恒定的。如果我拍摄线性布局的屏幕截图,它会给出屏幕上出现的屏幕截图,但 gridvew 包含的屏幕不止八个。 Gridview 在线性布局中用作垂直滚动条。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多