Android layout 使用文本标签制作可堆叠的方形图形

Android layout 使用文本标签制作可堆叠的方形图形,android-layout,Android Layout,对于我第一次进入安卓领域,我有一个在我看来很简单的项目。我想显示一个四角有文本的正方形图形。我希望能够显示单个图形或四个分组为2x2的图形 到目前为止,我发现在自定义GraphView上覆盖四个TextView的唯一方法是将GraphView放在RelativeLayout中,并相对于它定位TextView <?xml version="1.0" encoding="utf-8"?> <com.companyname.graph.GraphLayout xmlns:a

对于我第一次进入安卓领域,我有一个在我看来很简单的项目。我想显示一个四角有文本的正方形图形。我希望能够显示单个图形或四个分组为2x2的图形

到目前为止,我发现在自定义GraphView上覆盖四个TextView的唯一方法是将GraphView放在RelativeLayout中,并相对于它定位TextView

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

<com.companyname.graph.GraphView
    android:id="@+id/graph_single_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorGraphBackground"
    />

<TextView
    android:id="@+id/label_top_left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/graph_single_view"
    android:layout_alignStart="@+id/graph_single_view"
    android:layout_alignTop="@+id/graph_single_view"
    android:layout_gravity="top|start"
    android:gravity="top|start"
    android:hint="@string/placeholder_top_left"
    />

<TextView
    android:id="@+id/label_top_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/graph_single_view"
    android:layout_alignRight="@+id/graph_single_view"
    android:layout_alignTop="@+id/graph_single_view"
    android:layout_gravity="top|end"
    android:gravity="top|end"
    android:hint="@string/placeholder_top_right"
    />

<TextView
    android:id="@+id/label_bottom_left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/graph_single_view"
    android:layout_alignLeft="@+id/graph_single_view"
    android:layout_alignStart="@+id/graph_single_view"
    android:layout_gravity="bottom|start"
    android:gravity="bottom|start"
    android:hint="@string/placeholder_bottom_left"
    />

<TextView
    android:id="@+id/label_bottom_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/graph_single_view"
    android:layout_alignEnd="@+id/graph_single_view"
    android:layout_alignRight="@+id/graph_single_view"
    android:layout_gravity="bottom|end"
    android:gravity="bottom|end"
    android:hint="@string/placeholder_bottom_right"
    />

</com.companyname.graph.GraphLayout>
(从……偷来的)

不过,在展示四人小组时,我遇到了一些问题。GridLayout一想到就失去了它小小的头脑(它将每个图形视图放在整个屏幕宽度的区域中)。最后,我在一个垂直线性布局中使用了两个水平线性布局,使用布局和权重调整大小,这很有效,但不允许我进行我想要的动画过渡。我想要一个简单的图来扩展到整个区域,在移动的过程中剪切它不变的兄弟,然后再返回

到目前为止,我已经决定在LinearLayouts中设置布局权重的动画,但效果并不是你想向朋友炫耀的

我对所有内容都使用了包裹内容的高度和宽度,除了两行图之间以及四视图中的行之间的1IP宽/高分隔线

所以我的(第一个)问题是-有没有更好的方法来制作我的图形加文本小部件

@Override
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec )
{
    super.onMeasure( widthMeasureSpec, heightMeasureSpec );
    int size = Math.min( getMeasuredWidth(), getMeasuredHeight() );
    setMeasuredDimension( size, size );
}