嗨,我想在不移动叠加视图的情况下裁剪图像而不是移动图像。

图像可以四处移动。我想裁剪并保存突出显示的区域,如下所示在黑色边框内。
我有ImageView与android:scaleType="matrix"
这是我的布局代码
<RelativeLayout
android:id="@+imageEdit/rl_ScaleImage"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+imageEdit/Topbar"
android:visibility="visible" >
<ImageView
android:id="@+imageEdit/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:scaleType="matrix" />
<View
android:id="@+imageEdit/viewTop"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#99000000" />
<View
android:id="@+imageEdit/view_scaledImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+imageEdit/viewBottom"
android:layout_below="@+imageEdit/viewTop"
android:background="@drawable/rounded_corner_small" />
<View
android:id="@+imageEdit/viewBottom"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:background="#99000000" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
ImageView有OnTouchListener. 图像可以放大或缩小,也可以移动ImageView1。Viewview_scaledImage是我想要裁剪和保存的区域。我该怎么做呢?
我使用SherlockFragmentActivity作为我的主要活动类.下面是代码......
public class MainActivity extends SherlockFragmentActivity{
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar ab = getSherlock().getActionBar();
LayoutInflater li = LayoutInflater.from(this);
View customView = li.inflate(R.layout.my_custom_layout, null);
customView.setLayoutParams(new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT ,ActionBar.LayoutParams.MATCH_PARENT));
ab.setCustomView(customView);
ab.setDisplayShowHomeEnabled(false);} }
Run Code Online (Sandbox Code Playgroud)
我也尝试过
getSupportActionBar().setCustomView(customView);
Run Code Online (Sandbox Code Playgroud)
这是我的my_custom_layout.xml文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/light_gradient" >
<Button
android:id="@+id/btn_actionbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textSize="15sp"
android:text="Settings" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="20sp"
android:textColor="@color/White"
android:text="Home"/></RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我在清单文件中定义了我的活动,如下所示
<activity
android:name="com.example.demo.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock.Light" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.actionbarsherlock.sample.demos.EXAMPLE" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我无法设置我的actiobar的自定义视图.谁能帮我.Thanx提前.