[英]android - side by side buttons with scroll view
I'm trying to create a layout that has two buttons of equal width across the top of the screen and then a scroll view directly beneath it. 我正在尝试创建一个布局,该布局在屏幕顶部具有两个等宽的按钮,然后在其正下方有一个滚动视图。 I have a linearLayout inside of the scroll view because that's where i'm creating UI elements dynamically.
我在滚动视图中有一个linearLayout,因为这是我动态创建UI元素的地方。
The buttons are positioned correctly but my scroll view is hidden or the linearlayout inside of the scrollview is hidden, i can't tell and don't know enough about layouts to determine what's happening. 按钮的位置正确,但是我的滚动视图被隐藏,或者滚动视图内部的linearlayout被隐藏,我无法知道也不知道足够的布局来确定正在发生的事情。 What am i doing wrong?
我究竟做错了什么? I've created a TextView placeholder in the LinearLayout to tell if i can see anything and it's not showing up.
我在LinearLayout中创建了一个TextView占位符,以告诉我是否可以看到任何东西,但它没有显示出来。
<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>
Got it! 得到它了! thanks to you guys.
谢谢你们。 Fixed version below.
下面的固定版本。
<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>
You must place all UI elements inside of a single parent Layout. 您必须将所有UI元素放在单个父布局内。 I suggest that you can still use a
LinearLayout
as your top level, but it should be vertical, like this: 我建议您仍然可以将
LinearLayout
用作顶层,但是它应该是垂直的,如下所示:
android:orientation="vertical"
Within the parent vertical LinearLayout you may place a horizontal LinearLayout for the top buttons AND a ScrollView
. 在父垂直LinearLayout中,您可以为顶部按钮和
ScrollView
放置水平LinearLayout。 That should do it. 那应该做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.