简体   繁体   English

Android:RelativeLayout的ScrollView阻止按钮

[英]Android: ScrollView blocking buttons from RelativeLayout

My app currently looks like this: 我的应用当前如下所示:

在此处输入图片说明

When I click on a button , the border color changes to green as shown above. 当我单击button ,边框颜色变为绿色,如上所示。 I added a scrollview for my list of words as shown on the right side of the image. 我为单词列表添加了一个scrollview ,如图像右侧所示。 The problem is that this scrollview covers nearly the entire width of the screen and I am unable to click on the the first three rows of buttons . 问题是该scrollview几乎覆盖了屏幕的整个宽度,而我无法单击buttons前三行。

A brief description of the layout: 布局的简要说明:

I created a relative layout . 我创建了一个relative layout The 25 buttons are in this relative layout . 25个buttons处于此relative layout Then also within the relative layout I created a scrollable linear layout containing 20 textviews 然后在relative layout我创建了一个包含20个textviewsscrollable linear layout

Can someone please help me fix this layout? 有人可以帮我解决这个问题吗? I want to be able to click on all the buttons and have the scrollview not block the buttons . 我希望能够单击所有buttons并让scrollview不阻止buttons

And I thought it might be a good idea to put the 25 buttons in its own relative layout within the main relative layout . 我认为将25个buttons放在relative layout的主要relative layout是个好主意。 Does anyone know how I can do that without redoing the entire layout? 有谁知道我能在不重做整个布局的情况下做到这一点?

Also, if you guys have any advice on the correct way to code the layout please let me know. 另外,如果您对正确的布局编码方式有任何建议,请告诉我。 I am fairly knew to android programming and don't know if I should use relative layout vs linear layout vs frame layout or match_parent vs fill_parent vs wrap_content . 我对android编程相当了解,不知道是否应该使用relative layout vs linear layout vs frame layout或者match_parent vs fill_parent vs wrap_content Please let me know if I am misusing any of them. 如果我滥用其中任何一个,请告诉我。

<?xml version="1.0" encoding="utf-8"?>
<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=".Game" >

    <Button
        android:id="@+id/button1"
        android:layout_width="@dimen/size"
        android:layout_height="@dimen/size"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" />

.    
. (Buttons 2 - 24)
.    

    <Button
        android:id="@+id/button25"
        android:layout_width="@dimen/size"
        android:layout_height="@dimen/size"
        android:layout_alignBaseline="@+id/button24"
        android:layout_alignBottom="@+id/button24"
        android:layout_alignLeft="@+id/button20"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" />

    <ScrollView
        android:id="@+id/scrollable"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:scrollbars="vertical" >

        <LinearLayout
            android:id="@+id/ll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="300dp"
            android:layout_marginTop="20dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/word1" />

          .
          . (TextViews 2 - 19)
          .

            <TextView
                android:id="@+id/textView20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/word20" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

Use a LinearLayout instead of RelativeLayout as your top layout and make it android:orientation="horizontal". 使用LinearLayout而不是RelativeLayout作为顶部布局,并将其设置为android:orientation =“ horizo​​ntal”。

Then put all of your buttons in a RelativeLayout with an android:layout_weight="1" and android:layout_width="0dp". 然后将所有按钮放入带有android:layout_weight =“ 1”和android:layout_width =“ 0dp”的RelativeLayout中。

Also put the ScrollView in a second RelativeLayout with a width of "wrap_content". 还要将ScrollView放在第二个RelativeLayout中,其宽度为“ wrap_content”。

Here is the structure: 结构如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <RelativeLayout
        android:layout_widtht="0dp"
        android:layout_heigh="fill_parent"
        android:layout_weight="1">

        All buttons go here...

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent">

        Scroll view goes here...

    </RelativeLayout>
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM