2017-02-10 26 views
0

这里是我的代码:ChildView在过去的RelativeLayout无法看到当API> 20

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
> 
<Button 
    android:text="button" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    /> 
<TextView 
    android:text="right" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    /> 
</RelativeLayout> 

当API> 20,TextView的是盖的按钮,如何解决它,如果第一个孩子?是一个TextView,它不会发生。它在android中的错误?

回答

0

你有高度的根布局match_parent和宽度 您通过按钮与Android占据整个空间:layout_height = match_parent

和TextView中不使用参考按钮放置在布局相对布局提供android:layout_below属性,你可以使用它来放置你的textview下面的按钮

检查下面的例子会给你更多的细节

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <Button 
     android:text="button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/button" 
     android:background="#ffffff" 
     /> 
    <TextView 
     android:text="right" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/button" 
     android:layout_alignParentRight="true" 
     /> 
</RelativeLayout> 

突出显示:这不是你是不是在正确的方式使用它在android系统错误

+0

下工作的很好? – jemy

+0

添加屏幕截图你要如何? –

+0

我的声望低于10,所以我无法上传图片。如果您将我的代码复制到布局文件夹中,并选择低于21的预览api,您将得到它 – jemy

0

试试这个,

<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 
     <Button 
      android:text="button" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#ffffff" 
      android:layout_toLeftOf="@+id/tv_right" 
      /> 
     <TextView 
      android:id="@+id/tv_right" 
      android:text="right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      /> 
    </RelativeLayout> 
+0

这不是结果,我想want.i textview位于button.my代码右上角,如果我想要一个视图位于另一个视图的右上角,如何实现它,在api20 – jemy