[英]Android Add view to linearlayout in relativeLayout on button click
[英]Cannot click button within relativelayout that has linearlayout
以下是我的xml文件出现问题。 当我删除线性布局并将微调器放入relative_layout时,它可以正常工作,但是一旦将其放入Linear_layout中,就无法按下button和edit_box。 请帮忙。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<AutoCompleteTextView
android:id="@+id/trainid"
android:hint="@string/train"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true" />
<Button
android:id="@+id/button"
android:text="@string/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/traindetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/trainid"
android:text="" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/traindetails"
android:orientation="horizontal" >
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/selectcurrentstation"
android:spinnerMode="dropdown"
android:layout_weight="0.5" />
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/selecttargetstation"
android:spinnerMode="dropdown"
android:layout_weight="0.5" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/selectcurrentstation" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="@+id/table" />
</ScrollView>
</RelativeLayout>
当我将xml文件更改为此时,它工作正常。 但是我想要上面的布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<AutoCompleteTextView
android:id="@+id/trainid"
android:hint="@string/train"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:focusable="true" />
<Button
android:id="@+id/button"
android:text="@string/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:focusable="true" />
<TextView
android:id="@+id/traindetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/trainid"
android:text="" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/selectcurrentstation"
android:spinnerMode="dropdown"
android:layout_below="@id/traindetails" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/selecttargetstation"
android:spinnerMode="dropdown"
android:layout_below="@id/selectcurrentstation" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/selectcurrentstation" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="@+id/table" />
</ScrollView>
</RelativeLayout>
对第一个代码进行一些更改,您的代码即可正常工作。
微调器布局(用作表布局的父级)将layout_below ID更改为上方,即linear_layout1。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <AutoCompleteTextView android:id="@+id/trainid" android:hint="Train" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" /> <Button android:id="@+id/button" android:text="Search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" /> <TextView android:id="@+id/traindetails" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/trainid" android:text="" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/selectstation1" android:layout_below="@id/traindetails" android:orientation="horizontal" > <Spinner android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/selectcurrentstation" android:spinnerMode="dropdown" android:layout_weight="0.5" /> <Spinner android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/selecttargetstation" android:spinnerMode="dropdown" android:layout_weight="0.5" /> </LinearLayout> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/selectstation1" > <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1" android:id="@+id/table" /> </ScrollView> </RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.