为什么我的按钮“跟随”布局(xml)文件中的其他按钮?我拿第一个按钮(button1),如果我移动它,第二个按钮(button2)跟在第一个...我发现如果我改变了Eclipse右边部分的2个按钮的位置(如果我移动按钮1)在RelativeLayout组下的button2下,它继续..我能做什么???
<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="wrap_content"
android:gravity="top|center"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:onClick="audio"
android:src="@android:drawable/ic_lock_silent_mode_off" />
<ImageButton
android:id="@+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_alignTop="@+id/imageButton2"
android:layout_toRightOf="@+id/imageButton6"
android:onClick="wifi"
android:src="@android:drawable/stat_notify_sync" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageButton1"
android:layout_toRightOf="@+id/imageButton1"
android:onClick="teleph"
android:src="@android:drawable/ic_menu_call" />
<ImageButton
android:id="@+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton7"
android:layout_toRightOf="@+id/imageButton2"
android:onClick="nfc"
android:src="@android:drawable/ic_menu_info_details" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton7"
android:layout_alignTop="@+id/imageButton7"
android:layout_toRightOf="@+id/imageButton7"
android:onClick="touch"
android:src="@android:drawable/sym_def_app_icon" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton3"
android:layout_alignLeft="@+id/imageButton1"
android:layout_below="@+id/imageButton2"
android:layout_toLeftOf="@+id/imageButton6"
android:onClick="bluet"
android:src="@android:drawable/stat_sys_data_bluetooth" />
<ImageView
android:id="@+id/imageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="img"
android:scaleType="center"
android:src="@drawable/logo" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageButton6"
android:layout_alignRight="@+id/imageButton5"
android:layout_below="@+id/imageButton7"
android:onClick="camera"
android:src="@android:drawable/ic_menu_camera" />
答案 0 :(得分:0)
最简单的方法是将Buttons
中的每一组LinearLayout
打包并使用属性android:layout_below="@id/layoutIdAbove
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="@+id/LL1"
...
android:layout_below="@id/textView1"/>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:onClick="audio"
android:src="@android:drawable/ic_lock_silent_mode_off"
/>
<ImageButton
android:id="@+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_alignTop="@+id/imageButton2"
android:layout_toRightOf="@+id/imageButton6"
android:onClick="wifi"
android:src="@android:drawable/stat_notify_sync" />
</LinearLayout>
<LinearLayout
android:id="@+id/LL2"
...
android:layout_below="@id/LL1">
<! -- add next two Buttons and repeat -->