簡體   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