<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.main.MainFragment"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/text_one"
        android:layout_width="30dp"
        android:layout_height="match_parent"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="5sp"
        android:background="#3C8DC4"/>    <TextView
        android:id="@+id/text2"
        android:layout_width="30dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="5sp"
        android:background="#3C8"/></LinearLayout>这段代码哪出问题了,本来是要求text1和text2水平分布,但是结果是text2覆盖掉了text1;使用的Android studio,而且不能用Android:layout_toRightOf这个语法

解决方案 »

  1.   

    用你的代码跑了一下  没有问题啊
    模拟机效果
    activety_main.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="horizontal">    <TextView
            android:id="@+id/text_one"
            android:layout_width="30dp"
            android:layout_height="match_parent"
            android:text="TextView"
            android:textColor="#000000"
            android:textSize="5sp"
            android:background="#3C8DC4"/>    <TextView
            android:id="@+id/text2"
            android:layout_width="30dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="30dp"
            android:text="TextView"
            android:textColor="#000000"
            android:textSize="5sp"
            android:background="#3C8"/></LinearLayout>
      

  2.   

    Android:layout_toRightOf   线性布局不可以使用,相对布局可以使用代码是没问题的,你确定你引用的是这个布局吗?是不是引用别的布局去了,只是同名
      

  3.   

    我看很正常啊,蓝色的是textview1,绿色的是textview2,2 marginLeft=30dp,哪里覆盖了
      

  4.   

    代码没问题吧,toRightOf是RelativeLayout用的。
      

  5.   

    有个属性叫weight,即权重。会按照权重设置比例,比如说四个button的权重都是1,那么每个大小占25%