【问题标题】:How to save linearLayout and it's item as a image? [duplicate]如何将linearLayout及其项目保存为图像? [复制]
【发布时间】:2018-07-01 02:10:27
【问题描述】:

我正在开发一个报价应用程序,我想在线性布局的背景中设置图像,而不是在 android 中的 ImageView 中。

我的 linearLayout 包含两个文本视图。

我想将此布局保存在画廊中。谁能告诉我该怎么做

我使用的代码是:

在 XML 中:

<!-- language: lang-xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_margin="@dimen/card_margin"
    android:elevation="3dp"
    card_view:cardCornerRadius="@dimen/card_album_radius">

    <RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/lnquote1"        //my layout 
            android:layout_width="match_parent"
            android:layout_height="@dimen/_150sdp"
            android:gravity="center"
            android:background="@drawable/cheese_5"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/lnquote"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="@drawable/scrim"
                android:orientation="vertical">


                <TextView
                    android:id="@+id/quote"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textIsSelectable="true"
                    android:paddingLeft="@dimen/album_title_padding"
                    android:paddingRight="@dimen/album_title_padding"
                    android:paddingTop="@dimen/album_title_padding"
                    android:textColor="@color/white"
                    android:text="Quotes"
                    android:gravity="center"
                    android:typeface="serif"
                    android:textSize="@dimen/album_title" />

                <TextView
                    android:id="@+id/author"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="end"
                    android:paddingLeft="@dimen/album_title_padding"
                    android:paddingRight="@dimen/album_title_padding"
                    android:paddingTop="@dimen/album_title_padding"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    android:text=" -Author"
                    android:textColor="@color/white"
                    android:textSize="@dimen/album_title" />

            </LinearLayout>

        </LinearLayout>



        <View
            android:id="@+id/viline"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@id/lnquote1"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginBottom="5dp"
            android:background="@android:color/darker_gray" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:orientation="horizontal"
            android:layout_below="@id/viline">

            <LinearLayout
                android:id="@+id/lncopy"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal|center_vertical"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/imgcopy"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:scaleType="centerInside"
                    android:gravity="center"
                    android:background="@drawable/cop" />

                <TextView
                    android:id="@+id/txtcopy"
                    android:layout_width="wrap_content"
                    android:gravity="center"
                    android:layout_height="@dimen/ic_album_overflow_height"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="2dp"
                    android:textColor="@color/album_title"
                    android:text="Copy"/>

            </LinearLayout>
            <LinearLayout
                android:id="@+id/lnshare"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal|center_vertical"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/imgshare"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:scaleType="centerInside"
                    android:background="@drawable/sha" />

                <TextView
                    android:id="@+id/txtshare"
                    android:layout_width="wrap_content"
                    android:gravity="center"
                    android:layout_height="@dimen/ic_album_overflow_height"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="4dp"
                    android:textColor="@color/album_title"
                    android:text="Share"/>

            </LinearLayout>
            <LinearLayout
                android:id="@+id/lnfav"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal|center_vertical"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/imgfav"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:scaleType="centerInside"
                    android:tag="bg1"
                     />

            </LinearLayout>


        </LinearLayout>

    </RelativeLayout>

</android.support.v7.widget.CardView>

任何帮助将不胜感激

【问题讨论】:

  • 向我们展示您尝试过的 xml 代码
  • 请发布您的代码

标签: android bitmap android-linearlayout gallery


【解决方案1】:

简单使用,

LinearLayout view = (LinearLayout)findViewById(R.id.linearlayout);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();

【讨论】:

  • 谢谢,这对我有用。
猜你喜欢
  • 2012-10-12
  • 1970-01-01
  • 2011-07-16
  • 2012-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
相关资源
最近更新 更多