对不起,我可能愚蠢的问题,但我是一个初学者。 我有“相对”正方形布局,我需要在这个正方形布局中插入按钮,这个布局的大小和位置相对变化。这些参数将取决于正方形布局的尺寸。在第一张照片是一个方形布局的尝试,我想放置按钮。第二张图片显示可能看起来像结果。 Sry for my english :)相对放置按钮的方形布局 - Android
谢谢您的意见。
这是我squarelayout.java
package com.example.squarelayout;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
public class SquareView extends View {
public SquareView(Context context) {
super(context);
}
public SquareView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(size, size);
}
}
这是我activity_main.xml中
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="horizontal"
android:weightSum="100">
<com.example.squarelayout.SquareView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="100"
android:background="#f00"
android:orientation="horizontal" />
</LinearLayout>
</FrameLayout>
和你真的想要什么? – Lal
尝试使用RelativeLayout作为您的按钮想要移动的表面。这样,您可以通过设置上下左右边距来轻松更改位置。 – Krish
同意克里什改为RelativeLayout,然后只需拖放一个按钮小部件多数民众赞成在所有:) – BiggDawgg