Java android-带滚动视图的并排按钮
我试图创建一个布局,在屏幕顶部有两个宽度相等的按钮,然后在其正下方有一个滚动视图。我在scroll视图中有一个linearLayout,因为这是我动态创建UI元素的地方 按钮的位置正确,但我的滚动视图被隐藏,或者滚动视图内部的线性布局被隐藏,我无法判断,也不知道有关布局的足够信息,以确定发生了什么。我做错了什么?我在LinearLayout中创建了一个TextView占位符,告诉我是否可以看到任何东西,但它没有显示出来Java android-带滚动视图的并排按钮,java,android,layout,Java,Android,Layout,我试图创建一个布局,在屏幕顶部有两个宽度相等的按钮,然后在其正下方有一个滚动视图。我在scroll视图中有一个linearLayout,因为这是我动态创建UI元素的地方 按钮的位置正确,但我的滚动视图被隐藏,或者滚动视图内部的线性布局被隐藏,我无法判断,也不知道有关布局的足够信息,以确定发生了什么。我做错了什么?我在LinearLayout中创建了一个TextView占位符,告诉我是否可以看到任何东西,但它没有显示出来 <LinearLayout xmlns:android="http:/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/EditRecordOuterLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/Bforeground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/cancelButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:text="Cancel" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/cancelButtonText"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:src="@drawable/cancel" />
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/Bforeground"
android:layout_alignLeft="@id/Bforeground"
android:layout_alignRight="@id/Bforeground"
android:layout_alignTop="@+id/Bforeground"
android:onClick="clickedMe"
android:gravity="center" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/foreground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:text="Save" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/button_text"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:src="@drawable/save" />
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/foreground"
android:layout_alignLeft="@id/foreground"
android:layout_alignRight="@id/foreground"
android:layout_alignTop="@+id/foreground"
android:onClick="clickedMe"
android:gravity="center" />
</RelativeLayout>
</LinearLayout>
<ScrollView
android:id="@+id/editRecordScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/editRecordLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/someText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:text="This text should be showing..." />
</LinearLayout>
</ScrollView>
明白了!谢谢你们。修正了下面的版本
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/EditRecordOuterLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/Bforeground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/cancelButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:text="Cancel" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/cancelButtonText"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:src="@drawable/cancel" />
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/Bforeground"
android:layout_alignLeft="@id/Bforeground"
android:layout_alignRight="@id/Bforeground"
android:layout_alignTop="@+id/Bforeground"
android:onClick="clickedMe"
android:gravity="center" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/foreground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:text="Save" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/button_text"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:src="@drawable/save" />
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/foreground"
android:layout_alignLeft="@id/foreground"
android:layout_alignRight="@id/foreground"
android:layout_alignTop="@+id/foreground"
android:onClick="clickedMe"
android:gravity="center" />
</RelativeLayout>
</LinearLayout>
<ScrollView
android:id="@+id/editRecordScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/editRecordLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
必须将所有UI元素放置在单个父布局中。 我建议您仍然可以使用
线性布局
作为顶层,但它应该是垂直的,如下所示:
android:orientation="vertical"
在父垂直线性布局中,您可以放置顶部按钮的水平线性布局和滚动视图。
这应该就够了。我假设所有这些都包含在一个带有android:orientation=“vertical”的系统中?是的,对不起。代码的第一行没有缩进。修正了。