2014-04-19 6 views
0

I want to move center image and want to show that this image shown on the webicon image and lock images respectively. 안녕하세요 저는 3 개의 이미지 뷰를 사용하는 간단한 레이아웃을 만들었습니다. 는 그녀가 내 레이아웃 클래스 main.xml에 있습니다 : - 다음Android 레이아웃이 작동하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <view class="com.example.screenlock.MainActivity$IV" 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="center" 
     /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|fill_horizontal" 
     android:background="#60000000" 
     android:orientation="horizontal" 
     android:padding="7dp" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:scaleType="fitXY" 
      android:layout_alignParentLeft="true" 
      android:src="@drawable/browser1" /> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/circle" /> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right|fill_vertical" 
      android:layout_weight="0" 
      android:scaleType="fitXY" 
      android:src="@drawable/lock" /> 
    </LinearLayout> 

</FrameLayout> 

내 MainActivity.java 클래스가 될 때 : -

public class MainActivity extends Activity { 
private ImageView imageView1, imageView2; 

public static class IV extends ImageView { 
    private MainActivity mActivity; 
    public IV(Context context) { 
     super(context); 
    } 
    public IV(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
    public void setActivity(MainActivity act) { 
     mActivity = act; 
    } 
    public void onSystemUiVisibilityChanged(int visibility) { 
     mActivity.getState().onSystemUiVisibilityChanged(visibility); 
    } 
} 

private interface State { 
    void apply(); 
    State next(); 
    void onSystemUiVisibilityChanged(int visibility); 
} 
State getState() { 
    return mState; 
} 

static int TOAST_LENGTH = 500; 
IV mImage; 
TextView mText1, mText2; 
State mState; 

public MainActivity() { 
    // TODO Auto-generated constructor stub 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.activity_main); 

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_main); 
    startService(new Intent(this, MyLockService.class)); 
    System.out.println(R.id.image); 


    imageView2 = (ImageView)findViewById(R.id.imageView2); 

    imageView2.setOnTouchListener(new OnTouchListener() 
    { 
     float lastX; 
     PointF DownPT = new PointF(); // Record Mouse Position When Pressed Down 
     PointF StartPT = new PointF(); // Record Start Position of 'img' 

     @SuppressLint("NewApi") 
     @Override 
     public boolean onTouch(View v, MotionEvent event) 
     { 

      int eid = event.getAction(); 
      switch (eid) 
      { 
       case MotionEvent.ACTION_MOVE : 

        PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y); 
        if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){ 

         v.scrollBy((int) (event.getX()-lastX), 0); 
         lastX = event.getX(); 
         if(lastX >= 170){ 
          MarginLayoutParams lp = (MarginLayoutParams) imageView2.getLayoutParams(); 
          lp.setMargins(178, 0, 0, 0); 
          imageView2.setLayoutParams(lp); 

         } 

         if(lastX <= 25){ 
          MarginLayoutParams lp = (MarginLayoutParams) imageView2.getLayoutParams(); 
          lp.setMargins(0, -16, 0, 0); 
          imageView2.setLayoutParams(lp); 
         } 
         System.out.println("XXXXXXX "+lastX); 

        } 
        else{ 

         imageView2.setX((int)(StartPT.x+mv.x)); 
         imageView2.setY((int)(StartPT.y+mv.y)); 
         StartPT = new PointF(imageView2.getX(), imageView2.getY()); 


        //System.out.println("X: "+imageView2.getX()+"Y: "+imageView2.getY()); 
        if(imageView2.getX() < -70) 
        { 
         imageView2.setX(-103); 
         imageView2.setY(6); 
         //System.out.println("--------------------------------------"); 


        } 
        else if(imageView2.getX() > 260) 
        { 
         imageView2.setX(270); 
         imageView2.setY(8); 
         finish(); 
        } 
        } 

        break; 
       case MotionEvent.ACTION_DOWN : 
        if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){ 
         lastX = event.getX(); 
        } 
        else{ 

         DownPT.x = event.getX(); 
         DownPT.y = event.getY(); 
         StartPT = new PointF(imageView2.getX(), imageView2.getY()); 
        } 

        break; 
       case MotionEvent.ACTION_UP : 
        v.scrollTo(0, 0); 
        break; 
       default : 
        break; 
      } 
      return true; 
     } 
    }); 

} 


public void onWindowFocusChanged(boolean hasFocus) { 
    super.onWindowFocusChanged(hasFocus); 

    // Use onWindowFocusChanged to get the placement of 
    // the image because we have to wait until the image 
    // has actually been placed on the screen before we 
    // get the coordinates. That makes it impossible to 
    // do in onCreate, that would just give us (0, 0). 
    imageView1 = (ImageView) findViewById(R.id.imageView1); 
    int[] a = new int[2]; 
    imageView1.getLocationInWindow(a); 
    int x = a[0]; 
    int y = a[1]; 
    System.out.println("X "+x+" Y "+y); 
} 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

}

내가 사전에 벌집이 코드를 실행하고 에뮬레이터. 그러나 중심 이미지를 움직이면 왼쪽 이미지와 오른쪽 이미지 뒤에 각각 숨겨집니다. 나머지 두 이미지에 센터 이미지를 표시하고 두 이미지도 표시하려고합니다. 기본적으로 중심 이미지는 원이고 나머지 두 이미지는 브라우저 및 이미지 잠금이며 해당 원이 해당 이미지와 겹치기를 원합니다. 잠금 화면에서 작업 중입니다.

제 레이아웃 문제와 어떻게 해결할 수 있습니까? ????? 당신은 다음과 같이 레이아웃을 변경 시도 할 수 있습니다

답변

0

...

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <view 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.example.screenlock.MainActivity$IV" 
     android:scaleType="center" /> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|fill_horizontal" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#60000000" 
      android:orientation="horizontal" 
      android:padding="7dp" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" 
       android:scaleType="fitXY" 
       android:src="@drawable/ic_launcher" /> 

      <View 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" /> 

      <ImageView 
       android:id="@+id/imageView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right|fill_vertical" 
       android:layout_weight="0" 
       android:scaleType="fitXY" 
       android:src="@drawable/ic_launcher" /> 
     </LinearLayout> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:src="@drawable/ic_launcher" /> 
    </FrameLayout> 

</FrameLayout> 
+0

아니,이를 변경하여, 응용 프로그램 오류가 발생합니다. 그건 그렇고, 응용 프로그램이 잘 실행되고, 나는 단지 부분보기 및 터치 이동 부분에 문제가 있습니다. –

+0

@IqbalSingh ... 업데이트 된 답변보기. –

+0

괜찮습니다. 하지만 지금 내 이미지를 옮길 수 없다. –

관련 문제