繁体   English   中英

Android-正确定位视图

[英]Android - Correctly position views

在我的android中,我想要:-这里的“或”是一个文本视图。此文本视图被圆环视图包围,一条垂直线绕过圆环。

这是我的代码:-

此代码用于带有圆角的textview

可绘制文件夹中的round.xml :-

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <stroke android:color="#22ff55" android:width="3dip"/>

    <corners
        android:bottomLeftRadius="30dp"
        android:bottomRightRadius="30dp"
        android:topLeftRadius="30dp"
        android:topRightRadius="30dp" />

    <size
        android:height="60dp"
        android:width="60dp" />

</shape>

在我的布局中

我有textviews作为:

<TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/round_tv"
    android:gravity="center_vertical|center_horizontal"
    android:text="or"
    android:textColor="#000"
    android:textSize="20sp" />

而此代码为垂直线:-

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="#FF0000FF" />

所以我有带圆形的圆和一条垂直线的textview。

但是我的问题是如何才能加入这两个代码??? 或如果我的想法是错误的..我该如何实现这一目标?

最简单的方法是使圆和线成为.png图像,并使其成为带有文本的TextView的背景。

另外,如果可能的话,应避免将视图用于分隔线(如该行)。 视图一直是创建和布局视图的重中之重。 如果您有复杂的应用程序,它们会再次困扰您性能问题。

完成此操作后,您可以获取Textview并在FrameLayout中进行查看。 FrameLayout将帮助您显示对另一控件的控制

<FrameLayout 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
//Put here
</FrameLayout>

您可以将RelativeLayout用作上述所有视图的容器,并使用它来正确放置所有视图。

这是一个使您入门的示例:

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

 <Button
   android:id="@+id/btnRegister"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true" />

 <Button
   android:id="@+id/btnLogin"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentRight="true" />

  <View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:background="#FF0000FF" />

  <TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/round_tv"
    android:layout_centerInParent="true"
    android:text="or"
    android:textColor="#000"
    android:textSize="20sp" />


</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM