制作带文本标签的可堆叠方形图

时间:2016-03-23 00:41:38

标签: android-layout

对于我第一次进入Android版本的土地,我认为这是一个简单的项目。我想在四个角上显示带有文字的方形图。我希望能够显示一个图表,或者四个,分组为2 x 2。

Quad graph example

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

<?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>

为了保持GraphView方块,我在GraphView类中执行此操作:

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

(从here被盗)。

但是,在展示四人小组时,我遇到了问题。 GridLayout在思想上失去了它的微小思想(它将每个GraphView放在一个区域中,整个屏幕的宽度)。我最终在垂直LinearLayout中使用了两个水平LinearLayout,使用layout_weight来调整大小,但它不会让我做我想要的动画过渡。我想要一个简单的图表来扩展以覆盖整个区域,剪切其不变的兄弟姐妹,然后再回来。

到目前为止,我已经决定在LinearLayouts中设置layout_weights的动画效果,但效果不是你向朋友展示的效果。

我正在使用WRAP_CONTENT的高度和宽度,除了两行图形之间的1dip宽/高分隔线以及四边形视图中的行之间的所有内容。

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

0 个答案:

没有答案