简体   繁体   English

Android-正确定位视图

[英]Android - Correctly position views

In My android I want :-- here "Or" is a text view..this textview is surrounded by circle view and a vertical line is passing by the circle.. 在我的android中,我想要:-这里的“或”是一个文本视图。此文本视图被圆环视图包围,一条垂直线绕过圆环。

Here is my code:-- 这是我的代码:-

This code is for textview with rounded circle 此代码用于带有圆角的textview

round.xml in drawable folder:-- 可绘制文件夹中的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>

and in my layout 在我的布局中

I have textviews as: 我有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" />

and this code for vertical line:-- 而此代码为垂直线:-

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

So I have textview with rounded Circle and a verticle line.. 所以我有带圆形的圆和一条垂直线的textview。

But my problem is how can I join this two codes??? 但是我的问题是如何才能加入这两个代码??? or If my concept is wrong..How can I achieve that thing??????suggest me.. 或如果我的想法是错误的..我该如何实现这一目标?

Easiest way is to make the circle and line a .png image, and make it the background for a TextView with the text. 最简单的方法是使圆和线成为.png图像,并使其成为带有文本的TextView的背景。

Also, you should avoid using views for dividers (like that line) if at all possible. 另外,如果可能的话,应避免将视图用于分隔线(如该行)。 Views are fairly heavyweight to create and layout all the time. 视图一直是创建和布局视图的重中之重。 If you have a complex app they'll come back to bite you in performance issues. 如果您有复杂的应用程序,它们会再次困扰您性能问题。

As you have done this you can take the Textview and view inside the FrameLayout. 完成此操作后,您可以获取Textview并在FrameLayout中进行查看。 FrameLayout will help you show one control over the other FrameLayout将帮助您显示对另一控件的控制

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

You can use a RelativeLayout as the container for all the above views and use it to properly position all the views. 您可以将RelativeLayout用作上述所有视图的容器,并使用它来正确放置所有视图。

Here's an example to get you started: 这是一个使您入门的示例:

<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