2016-03-01 70 views
0

我正在尝试创建仪表。我有一个空白的PNG和第二个,尺寸完全相同,显示针。我的想法是将针头覆盖在仪表顶部,然后根据我希望显示的值旋转它。 我无法将一个图像放在另一个图像上。有谁知道如何做到这一点?图像位于LinearLayout内。创建仪表

+0

选项1:延长图像查看和开发自己的控制 –

+0

选项2:使用规图像作为背景的ImageView和把针作为src ...选项3 ....采取框架布局或相对布局...把两个图像视图1.测量仪和2.针 –

+0

这将有助于:http://stackoverflow.com/questions/12551295 /简单量表视图像速度计在Android中 –

回答

0

您可以使用RelativeLayout来做到这一点。

<RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:id="@+id/needle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:src="@drawable/needle" /> 

      <ImageView 
       android:id="@+id/cluster" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:src="@drawable/cluster" /> 

      <TextView 
       android:id="@+id/rpmVal" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="27dp" 
       android:text="00000" 
       android:textColor="#ffffff" 
       android:textSize="60sp" 
       android:textStyle="italic" /> 

      <TextView 
       android:id="@+id/textView23" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBaseline="@+id/rpmVal" 
       android:layout_alignBottom="@+id/rpmVal" 
       android:layout_toEndOf="@+id/rpmVal" 
       android:text="RPM" 
       android:textColor="#ffffff" /> 

      <TextView 
       android:id="@+id/textView24" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/rpmVal" 
       android:layout_marginBottom="40dp" 
       android:layout_toStartOf="@+id/textView23" 
       android:text="x100 rpm" 
       android:textColor="#ffffff" 
       android:textSize="10sp" /> 

     </RelativeLayout> 

这种设置建议立即进行删除这个样子: null

我希望我能帮助^^

+0

谢谢。这是我18个月前通过使用我在其他地方找到的自定义标尺完成的一个项目。实际上我打算很快重写它,所以我会尝试你的解决方案。 –