Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过其他按钮以编程方式删除按钮_Android_Button - Fatal编程技术网

Android 通过其他按钮以编程方式删除按钮

Android 通过其他按钮以编程方式删除按钮,android,button,Android,Button,我有一个删除按钮(btnDelete)。当我按下它时,我想删除其他“选定”按钮。 我不知道,我怎样才能在触摸屏上选择一些东西,或者决定现在应该删除哪个UI元素。 下面是我的活动的.xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/ove

我有一个删除按钮(btnDelete)。当我按下它时,我想删除其他“选定”按钮。 我不知道,我怎样才能在触摸屏上选择一些东西,或者决定现在应该删除哪个UI元素。 下面是我的活动的.xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/overViewLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:columnCount="6"
    android:orientation="vertical"
    tools:context="com.example.myexpenses.OverviewActivity" >

    <TextView
         android:id="@+id/tvOverViewTitel"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:layout_centerHorizontal="true"
         android:layout_marginTop="28dp"
         android:text="Übersicht"
         android:textColor="#ffffffff"
         android:textSize="24dp"
         android:textStyle="bold" />


    <ScrollView android:layout_width="fill_parent"  android:layout_height="195dp" android:scrollbars="vertical"
                android:layout_marginTop="90dp">
    <LinearLayout android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="wrap_content">
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">
        <Button
            android:id="@+id/test11"
            android:layout_width="60dp"
            android:layout_height="60dp"            
            android:background="@drawable/selected_category"
            android:text="rechts1" />

        <Button
            android:id="@+id/test18831"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="right2" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">     
        <Button
            android:id="@+id/test141"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        <Button
            android:id="@+id/test533"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="fill_parent">      

        <Button
            android:id="@+id/test121"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        <Button
            android:id="@+id/test23"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">     

        <Button
            android:id="@+id/test1212212"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        <Button
            android:id="@+id/test2324"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">     

        <Button
            android:id="@+id/test121222112"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        <Button
            android:id="@+id/test2233"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">     

        <Button
            android:id="@+id/test12199"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        <Button
            android:id="@+id/test23232"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">     

        <Button
            android:id="@+id/test1111"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        <Button
            android:id="@+id/test23222"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/selected_category"
            android:text="links" />
        </LinearLayout>
     </LinearLayout>
     </ScrollView>

     <Button
        android:id="@+id/btnDelete"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignBaseline="@+id/btnAdd"
        android:layout_alignBottom="@+id/btnAdd"
        android:layout_alignParentRight="true"
        android:layout_marginRight="32dp"
        android:background="@drawable/delete" />

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="46dp"
        android:layout_marginRight="24dp"
        android:layout_toLeftOf="@+id/tvTitel"
        android:background="@drawable/add" />  


</RelativeLayout>

我不太理解您对问题的解释,但从标题来看,我认为这就是您希望在Java代码中执行的操作

Button btn = (Button)findViewById(R.layout.button)
btn.setVisibility(btn.GONE)
将其从布局中删除。或者

btn.setVisibility(btn.INVISIBLE)

这将隐藏它,因此它仍将占用空间

如果将ScrollView的高度设置为195dp,我认为这是您只看到一个按钮的主要原因。在您的情况下,可以使用“匹配父项”或“填充父项”



我似乎不明白你的意思,非常感谢。我刚改变了对我问题的描述。请看上面:)
 <ScrollView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">