【问题标题】:How do I position ZoomButtonsController in custom ImageView?如何在自定义 ImageView 中定位 ZoomButtonsController?
【发布时间】:2012-03-04 18:50:13
【问题描述】:

Android 中的布局让我相当困惑。 我正在慢慢实现一个自定义 ImageView,我想在其中使用 ZoomButtonsController。 但是,我想决定缩放按钮在布局中的位置,但我不知道如何将它们从默认的底部中心位置移动。

我一直在尝试在主要活动中布置简单的视图,例如按钮,这似乎正如我所猜测和期望的那样工作。 在 ZoomButtonsController 的情况下,我想重新定位它们。我使用 RelativeLayout 作为邮件布局,并在自定义 ImageView 中添加 ZoomButtonsController。

活动代码

public class ImageViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        CustomImageView imageView = new CustomImageView(this);
        relativeLayout.addView(imageView);
    }
}

CustomImageView 代码

public class CustomImageView extends ImageView {
    private ZoomButtonsController mZoomButtons;

    public CustomImageView(Context context) {
        super(context);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
        mZoomButtons = new ZoomButtonsController(this);
        mZoomButtons.getZoomControls();
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        setLayoutParams(layoutParams);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        Log.d("TAG", "touch");
        mZoomButtons.setVisible(true);
        return true;
    }
}

我已经在参数中使用 WRAP_CONTENT 进行了测试,但这只会使缩放按钮消失。

【问题讨论】:

标签: android layout imageview


【解决方案1】:

事实上,我无法以任何方式定位 ZoomButtonsController,最终不得不接受默认位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多