Я пытаюсь создать приложение PhotoFrame, для этого у меня есть рамка, и я добавляю изображение в эту рамку из галереи. Этот кадр находится в одном из макетов в главном макет, который я пытаюсь снять с экрана для этого макета.Android: Take Screen Shoot для макета
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/root"
tools:context="com.ccs.photoframe.MainActivity"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="vertical">
<Button
android:id="@+id/btn_select"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Select Photo"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8"
android:background="@drawable/photo_frame"
android:orientation="vertical"
>
<ImageView
android:id="@+id/img_save_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="70dp"
>
<ImageView
android:id="@+id/ivImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="matrix"/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="horizontal">
<Button
android:id="@+id/btn_save_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Save Photo"/>
</LinearLayout>
Я пытаюсь взять экрана стрелять в LinearLayout "layout_frame"
Я пытался ...
btn_save_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View v1 = layout_frame.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
img_save_photo = (ImageView) findViewById(R.id.img_save_photo);
img_save_photo.setVisibility(View.VISIBLE);
img_save_photo.setBackgroundDrawable(bitmapDrawable);
}
});
Но это снимает скриншот для всего макета.
Есть ли какой-либо возможный способ сделать съемку экрана для определенного места.
Заранее спасибо :)
Снимите 'getRootView()' вызов, если вы просто хотите 'layout_frame'. Фактически, просто используйте 'layout_frame'. Вам не нужно 'View v1'. –
Что вы подразумеваете под конкретным местоположением ... конкретный вид? –
извините, его конкретный вид @Sohail Zahid –