Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 儿童';地球引力被忽略了_Android_Layout Gravity - Fatal编程技术网

Android 儿童';地球引力被忽略了

Android 儿童';地球引力被忽略了,android,layout-gravity,Android,Layout Gravity,我有自定义布局(最终扩展视图组),其中包含2个ImageButton和1个自定义视图(扩展SurfaceView) 我的问题是,我的图像上的android:layout\u gravity=“center”不起作用。 此外,它甚至不会显示在xml编辑器的自动完成上 <com.technaim.elecbic.Circle android:id="@+id/action_circle" android:layout_width="wrap_content"

我有自定义布局(最终扩展视图组),其中包含2个ImageButton和1个自定义视图(扩展SurfaceView)
我的问题是,我的图像上的android:layout\u gravity=“center”不起作用。
此外,它甚至不会显示在xml编辑器的自动完成上

<com.technaim.elecbic.Circle
        android:id="@+id/action_circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />


<RelativeLayout 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:gravity="center"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainScreen" >

<com.technaim.elecbic.DragLayer
    android:id="@+id/drag_layer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.technaim.elecbic.Circle
        android:id="@+id/action_circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <ImageButton
        android:id="@+id/img_lock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="@null"
        android:contentDescription="@string/lock"
        android:src="@drawable/lock"
        android:clickable="false" 
        android:visibility="invisible"
        android:adjustViewBounds="true"/>

    <ImageButton
        android:id="@+id/img_unlock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="@null"
        android:contentDescription="@string/unlock"
        android:src="@drawable/unlock"
        android:clickable="false" 
        android:visibility="invisible"
        android:adjustViewBounds="true"/>
</com.technaim.elecbic.DragLayer>

<Button
    android:id="@+id/btn_track_device"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="@string/track_device" />

</RelativeLayout>

更新:
在子项上没有任何布局选项

    /*
 * This is a modified version of a class from the Android Open Source Project. 
 * The original copyright and license information follows.
 * 
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.technaim.elecbic;

import com.technaim.logic.DragController;
import com.technaim.logic.DragSource;
import com.technaim.logic.DropTarget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

/**
 * A ViewGroup that coordinates dragging across its dscendants.
 *
 * <p> This class used DragLayer in the Android Launcher activity as a model.
 * It is a bit different in several respects:
 * (1) It extends MyAbsoluteLayout rather than FrameLayout; (2) it implements DragSource and DropTarget methods
 * that were done in a separate Workspace class in the Launcher.
 */
public class DragLayer extends MyAbsoluteLayout 
    implements DragSource, DropTarget
{
    DragController mDragController;

    /**
     * Used to create a new DragLayer from XML.
     *
     * @param context The application's context.
     * @param attrs The attribtues set containing the Workspace's customization values.
     */
    public DragLayer (Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setDragController(DragController controller) {
        mDragController = controller;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return mDragController.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return mDragController.onTouchEvent(ev);
    }

    @Override
    public boolean dispatchUnhandledMove(View focused, int direction) {
        return mDragController.dispatchUnhandledMove(focused, direction);
    }

/**
 */
// DragSource interface methods

/**
  * This method is called to determine if the DragSource has something to drag.
  * 
  * @return True if there is something to drag
  */

public boolean allowDrag () {
    // In this simple demo, any view that you touch can be dragged.
    return true;
}

/**
 * setDragController
 *
 */

 /* setDragController is already defined. See above. */

/**
 * onDropCompleted
 *
 */

public void onDropCompleted (View target, boolean success)
{
    //toast ("DragLayer2.onDropCompleted: " + target.getId () + " Check that the view moved.");
}

/**
 */
// DropTarget interface implementation

/**
 * Handle an object being dropped on the DropTarget.
 * This is the where a dragged view gets repositioned at the end of a drag.
 * 
 * @param source DragSource where the drag started
 * @param x X coordinate of the drop location
 * @param y Y coordinate of the drop location
 * @param xOffset Horizontal offset with the object being dragged where the original
 *          touch happened
 * @param yOffset Vertical offset with the object being dragged where the original
 *          touch happened
 * @param dragView The DragView that's being dragged around on screen.
 * @param dragInfo Data associated with the object being dragged
 * 
 */

public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
    View v = (View) dragInfo;
    /*toast ("DragLayer2.onDrop accepts view: " + v.getId ()
          + "x, y, xO, yO :" + new Integer (x) + ", " + new Integer (y) + ", "
          + new Integer (xOffset) + ", " + new Integer (yOffset));*/

    int w = v.getWidth ();
    int h = v.getHeight ();
    int left = x - xOffset;
    int top = y - yOffset;
    DragLayer.LayoutParams lp = new DragLayer.LayoutParams (w, h, left, top);
    this.updateViewLayout(v, lp);
}

public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
}

public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
}

public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
}

/**
 * Check if a drop action can occur at, or near, the requested location.
 * This may be called repeatedly during a drag, so any calls should return
 * quickly.
 * 
 * @param source DragSource where the drag started
 * @param x X coordinate of the drop location
 * @param y Y coordinate of the drop location
 * @param xOffset Horizontal offset with the object being dragged where the
 *            original touch happened
 * @param yOffset Vertical offset with the object being dragged where the
 *            original touch happened
 * @param dragView The DragView that's being dragged around on screen.
 * @param dragInfo Data associated with the object being dragged
 * @return True if the drop will be accepted, false otherwise.
 */
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
    return true;
}

/**
 * Estimate the surface area where this object would land if dropped at the
 * given location.
 * 
 * @param source DragSource where the drag started
 * @param x X coordinate of the drop location
 * @param y Y coordinate of the drop location
 * @param xOffset Horizontal offset with the object being dragged where the
 *            original touch happened
 * @param yOffset Vertical offset with the object being dragged where the
 *            original touch happened
 * @param dragView The DragView that's being dragged around on screen.
 * @param dragInfo Data associated with the object being dragged
 * @param recycle {@link Rect} object to be possibly recycled.
 * @return Estimated area that would be occupied if object was dropped at
 *         the given location. Should return null if no estimate is found,
 *         or if this target doesn't provide estimations.
 */
public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo, Rect recycle)
{
    return null;
}

/**
 */
// More methods

/**
 * Show a string on the screen via Toast.
 * 
 * @param msg String
 * @return void
 */


} // end class
/*
*这是Android开源项目中一个类的修改版本。
*原始版权和许可证信息如下。
* 
*版权所有(C)2008安卓开源项目
*
*根据Apache许可证2.0版(以下简称“许可证”)获得许可;
*除非遵守许可证,否则不得使用此文件。
*您可以通过以下方式获得许可证副本:
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*除非适用法律要求或书面同意,软件
*根据许可证进行的分发是按“原样”进行分发的,
*无任何明示或暗示的保证或条件。
*请参阅许可证以了解管理权限和权限的特定语言
*许可证下的限制。
*/
包com.technaim.elecbic;
导入com.technaim.logic.DragController;
导入com.technaim.logic.DragSource;
导入com.technaim.logic.DropTarget;
导入android.content.Context;
导入android.graphics.Rect;
导入android.util.AttributeSet;
导入android.view.MotionEvent;
导入android.view.KeyEvent;
导入android.view.view;
导入android.widget.Toast;
/**
*一种视图组,用于协调在其数据中心上拖动。
*
*该类使用Android Launcher活动中的DragLayer作为模型。
*这在几个方面有点不同:
*(1)它扩展了MyAbsoluteLayout而不是FrameLayout;(2) 它实现了DragSource和DropTarget方法
*这是在启动器中的一个单独的工作区类中完成的。
*/
公共类DragLayer扩展了MyAbsoluteLayout
实现DragSource、DropTarget
{
牵引控制器;
/**
*用于从XML创建新的DragLayer。
*
*@param context应用程序的上下文。
*@param attrs包含工作区自定义值的属性集。
*/
公共DragLayer(上下文、属性集属性){
超级(上下文,attrs);
}
公共无效设置DragController(DragController控制器){
mDragController=控制器;
}
@凌驾
公共布尔dispatchKeyEvent(KeyEvent事件){
返回mDragController.dispatchKeyEvent(事件)| | super.dispatchKeyEvent(事件);
}
@凌驾
公共布尔值onInterceptTouchEvent(MotionEvent ev){
返回mDragController.onInterceptTouchEvent(ev);
}
@凌驾
公共事件(MotionEvent ev){
返回mDragController.onTouchEvent(ev);
}
@凌驾
公共布尔dispatchUnhandledMove(以视图为中心,整数方向){
返回mDragController.dispatchUnhandledMove(聚焦,方向);
}
/**
*/
//DragSource接口方法
/**
*调用此方法以确定DragSource是否有要拖动的内容。
* 
*@如果有东西要拖,返回True
*/
公共布尔allowDrag(){
//在这个简单的演示中,可以拖动您触摸的任何视图。
返回true;
}
/**
*设置拖动控制器
*
*/
/*setDragController已定义。请参见上文*/
/**
*onDropCompleted
*
*/
public void onDropCompleted(查看目标,布尔值成功)
{
//toast(“DragLayer2.onDropCompleted:”+target.getId()+“检查视图是否移动”);
}
/**
*/
//DropTarget接口实现
/**
*处理正在DropTarget上丢弃的对象。
*这是拖动视图在拖动结束时重新定位的位置。
* 
*@param source DragSource开始拖动的位置
*@param x放置位置的坐标
*放置位置的@param y坐标
*@param xOffset水平偏移,对象拖动到原始
*接触发生了
*@param yOffset垂直偏移,对象拖动到原始
*接触发生了
*@param dragView屏幕上正在拖动的dragView。
*@param dragInfo与正在拖动的对象关联的数据
* 
*/
public void onDrop(DragSource源、int x、int y、int xOffset、int yOffset、,
DragView DragView,对象dragInfo)
{
视图v=(视图)绘图;
/*toast(“DragLayer2.onDrop接受视图:”+v.getId()
+“x,y,xO,yO:“+新整数(x)+”,“+新整数(y)+”,”
+新整数(xOffset)+“,”+新整数(yOffset))*/
intw=v.getWidth();
inth=v.getHeight();
int left=x-xOffset;
int top=y-偏移量;
DragLayer.LayoutParams lp=新的DragLayer.LayoutParams(宽、高、左、上);
此。更新视图布局(v,lp);
}
public void onDragEnter(DragSource源、int x、int y、int xOffset、int yOffset、,
DragView DragView,对象dragInfo)
{
}
public void onDragOver(DragSource source,int x,int y,int xOffset,int yOffset,
DragView DragView,对象dragInfo)
{
}
public void onDragExit(DragSource源、int x、int y、int xOffset、int yOffset、,
DragView DragView,对象dragInfo)
{
}
/**
*检查是否可以在请求的位置或其附近执行放置操作。
*在拖动过程中可能会重复调用,因此任何调用都应返回
*快点。
* 
*@param source DragSource开始拖动的位置
*@param x放置位置的坐标
*放置位置的@param y坐标
*@param xOffset水平偏移,对象拖动到
*最初的接触发生了
*@param yOffset垂直偏移,拖动对象时
*最初的接触发生了
*@param dragView屏幕上正在拖动的dragView。
*@param dragInfo数据协会
    /*
 * This is a modified version of a class from the Android Open Source Project. 
 * The original copyright and license information follows.
 * 
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.technaim.elecbic;

import com.technaim.logic.DragController;
import com.technaim.logic.DragSource;
import com.technaim.logic.DropTarget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

/**
 * A ViewGroup that coordinates dragging across its dscendants.
 *
 * <p> This class used DragLayer in the Android Launcher activity as a model.
 * It is a bit different in several respects:
 * (1) It extends MyAbsoluteLayout rather than FrameLayout; (2) it implements DragSource and DropTarget methods
 * that were done in a separate Workspace class in the Launcher.
 */
public class DragLayer extends MyAbsoluteLayout 
    implements DragSource, DropTarget
{
    DragController mDragController;

    /**
     * Used to create a new DragLayer from XML.
     *
     * @param context The application's context.
     * @param attrs The attribtues set containing the Workspace's customization values.
     */
    public DragLayer (Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setDragController(DragController controller) {
        mDragController = controller;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return mDragController.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return mDragController.onTouchEvent(ev);
    }

    @Override
    public boolean dispatchUnhandledMove(View focused, int direction) {
        return mDragController.dispatchUnhandledMove(focused, direction);
    }

/**
 */
// DragSource interface methods

/**
  * This method is called to determine if the DragSource has something to drag.
  * 
  * @return True if there is something to drag
  */

public boolean allowDrag () {
    // In this simple demo, any view that you touch can be dragged.
    return true;
}

/**
 * setDragController
 *
 */

 /* setDragController is already defined. See above. */

/**
 * onDropCompleted
 *
 */

public void onDropCompleted (View target, boolean success)
{
    //toast ("DragLayer2.onDropCompleted: " + target.getId () + " Check that the view moved.");
}

/**
 */
// DropTarget interface implementation

/**
 * Handle an object being dropped on the DropTarget.
 * This is the where a dragged view gets repositioned at the end of a drag.
 * 
 * @param source DragSource where the drag started
 * @param x X coordinate of the drop location
 * @param y Y coordinate of the drop location
 * @param xOffset Horizontal offset with the object being dragged where the original
 *          touch happened
 * @param yOffset Vertical offset with the object being dragged where the original
 *          touch happened
 * @param dragView The DragView that's being dragged around on screen.
 * @param dragInfo Data associated with the object being dragged
 * 
 */

public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
    View v = (View) dragInfo;
    /*toast ("DragLayer2.onDrop accepts view: " + v.getId ()
          + "x, y, xO, yO :" + new Integer (x) + ", " + new Integer (y) + ", "
          + new Integer (xOffset) + ", " + new Integer (yOffset));*/

    int w = v.getWidth ();
    int h = v.getHeight ();
    int left = x - xOffset;
    int top = y - yOffset;
    DragLayer.LayoutParams lp = new DragLayer.LayoutParams (w, h, left, top);
    this.updateViewLayout(v, lp);
}

public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
}

public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
}

public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
}

/**
 * Check if a drop action can occur at, or near, the requested location.
 * This may be called repeatedly during a drag, so any calls should return
 * quickly.
 * 
 * @param source DragSource where the drag started
 * @param x X coordinate of the drop location
 * @param y Y coordinate of the drop location
 * @param xOffset Horizontal offset with the object being dragged where the
 *            original touch happened
 * @param yOffset Vertical offset with the object being dragged where the
 *            original touch happened
 * @param dragView The DragView that's being dragged around on screen.
 * @param dragInfo Data associated with the object being dragged
 * @return True if the drop will be accepted, false otherwise.
 */
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
        DragView dragView, Object dragInfo)
{
    return true;
}

/**
 * Estimate the surface area where this object would land if dropped at the
 * given location.
 * 
 * @param source DragSource where the drag started
 * @param x X coordinate of the drop location
 * @param y Y coordinate of the drop location
 * @param xOffset Horizontal offset with the object being dragged where the
 *            original touch happened
 * @param yOffset Vertical offset with the object being dragged where the
 *            original touch happened
 * @param dragView The DragView that's being dragged around on screen.
 * @param dragInfo Data associated with the object being dragged
 * @param recycle {@link Rect} object to be possibly recycled.
 * @return Estimated area that would be occupied if object was dropped at
 *         the given location. Should return null if no estimate is found,
 *         or if this target doesn't provide estimations.
 */
public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo, Rect recycle)
{
    return null;
}

/**
 */
// More methods

/**
 * Show a string on the screen via Toast.
 * 
 * @param msg String
 * @return void
 */


} // end class