我在这里搜索了很多,并尝试提供有关如何在我的相对布局中对齐子对象的信息,但是其中一个不显示。
这是我的代码:
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@id/textView1"
android:layout_below="@id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="example"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/textView2"
android:layout_alignBottom="@id/textView2"
android:text="example" />
</RelativeLayout>
TextView3根本没有出现。看起来似乎有一个缺失或冲突的规则,但我无法弄清楚哪一个。
答案 0 :(得分:1)
textView2与左侧对齐。如果将textView3对齐到左侧对象的左侧,它将不在屏幕上
答案 1 :(得分:1)
您的代码不提供textView1的代码,但是如果我假设您的textView1位于屏幕的左上方,那么如果您的内部RelativeLayout有此行:
机器人:layout_alignLeft = “@ ID / textView1”
textView2将与textView1对齐,因此,如果添加了textView3,则会添加并执行:
机器人:layout_toLeftOf = “@ ID / textView2”
然后它会出现在屏幕左侧。
答案 2 :(得分:0)
来吧试一试,对我有用。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="example"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:text="example"
/>
</RelativeLayout>
答案 3 :(得分:0)
我在这里看的东西,例如使用相对布局,你需要具体,如果你想在这种情况下定位到editTextNumberPeriods的右边,你还需要指示.xml textView2在哪里,在这种情况下它在下面btn18,我的意思是指示 .xml 是右还是左是不够的。我测试过,效果很好。
<TextView
**android:id="@+id/btn18"**
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:gravity="center"
android:textAllCaps="false"
android:layout_centerHorizontal="true"
android:layout_below="@id/btn19"
android:text="Please enter numbers of periods." />
<EditText
**`android:id="@+id/editTextNumberPeriods"`**
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn18"
android:cursorVisible="true"
android:focusable="true"
android:fontFamily="sans-serif"
android:layout_centerHorizontal="true"
android:ems="10"
android:gravity="center"
android:background="#68DBFA"
android:hint="numbers of periods"
android:textColorHint="@color/white"
android:inputType="number"
android:selectAllOnFocus="true"
android:textAllCaps="false"
android:textColor="#7C1616" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:layout_below="@id/btn18"
android:layout_toRightOf="@id/editTextNumberPeriods"**
android:text="TextView" />