在android xml中将texttext放在textview的上方和下方

时间:2014-10-15 07:15:15

标签: android xml android-layout android-xml

我正在尝试在textview上方放置一个editview,它位于中心垂直和水平位置。和textview下面的其他编辑视图。

我添加了广告布局,现在编辑视图显示在左上角。

我正在使用嵌套的相对布局。

以下是代码:

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/love"
tools:context="com.ashsoftapps.lovecalculator.MainActivity" >



 <RelativeLayout
     android:id="@+id/lay"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
    android:layout_above="@+id/adView"
      >

     <TextView
         android:id="@+id/textView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:text="Txt "
         android:textSize="30dp"
         android:textStyle="bold" />



     <EditText
         android:id="@+id/editText1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_above="@+id/textView1"
         android:layout_marginBottom="30dp"
         android:ems="10"
         android:hint="Name 1" >

         <requestFocus />
     </EditText>

     <EditText
         android:id="@+id/editText2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/textView1"
         android:layout_marginTop="15dp"
         android:ems="10"
         android:hint="Name 2" />


   <ImageButton
         android:id="@+id/imageButton1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_centerHorizontal="true"
         android:layout_marginBottom="14dp"
         android:src="@drawable/sub"
         android:visibility="visible" />

 </RelativeLayout>
   <com.google.android.gms.ads.AdView
     android:id="@+id/adView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
   >
 </com.google.android.gms.ads.AdView>

2 个答案:

答案 0 :(得分:0)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
  android:layout_height="fill_parent"

android:background="@drawable/love"  >


 <TextView
     android:id="@+id/textView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
      android:layout_centerInParent="true"
     android:text="Txt "
     android:textSize="30dp"
     android:textStyle="bold" />



 <EditText
     android:id="@+id/editText1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/textView1"
     android:layout_marginBottom="30dp"
     android:ems="10"
     android:hint="Name 1" > 
 </EditText>

     <EditText
     android:id="@+id/editText2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@+id/textView1"
     android:layout_marginTop="15dp"
     android:ems="10"
     android:hint="Name 2" />


    <ImageButton
     android:id="@+id/imageButton1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/adView"
     android:layout_centerHorizontal="true"
     android:layout_marginBottom="14dp"
     android:src="@drawable/sub"
     android:visibility="visible" />

   <com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
      android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
   android:layout_centerInParent="true"
   >
  </com.google.android.gms.ads.AdView>
  </RelativeLayout>

答案 1 :(得分:0)

这将对您有所帮助:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:ads="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/love"  >
    <TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:text="Txt "
      android:textSize="30dp"
      android:textStyle="bold" />



   <EditText
     android:id="@+id/editText1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/textView1"
     android:layout_centerHorizontal="true"
     android:layout_marginBottom="30dp"
     android:ems="10"
     android:hint="Name 1" > 
   </EditText>

   <EditText
     android:id="@+id/editText2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@+id/textView1"
     android:layout_centerHorizontal="true"
     android:layout_marginTop="15dp"
     android:ems="10"
     android:hint="Name 2" />


   <ImageButton
     android:id="@+id/imageButton1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/adView"
     android:layout_centerHorizontal="true"
     android:layout_marginBottom="14dp"
     android:src="@drawable/sub"
     android:visibility="visible" />

  <com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true">
 </com.google.android.gms.ads.AdView>
</RelativeLayout>
相关问题