Android 对齐控件
我只是在浪费时间,因为我不知道该怎么做。基本上,我想有一个自定义输入视图,用户可以用手指画出他/她的任何东西,在它下面,我想放置2个(或者更多)按钮,我不想在自定义视图的顶部重叠。因为我试图避免硬编码宽度和高度,有没有办法指定按钮应环绕到其内容,而自定义视图应占据剩余高度?因为我希望所有按钮都具有相同的高度,所以我想以其中一个按钮的高度作为参考应该会起到某种作用 以下是我当前的布局:Android 对齐控件,android,android-layout,css-position,android-relativelayout,Android,Android Layout,Css Position,Android Relativelayout,我只是在浪费时间,因为我不知道该怎么做。基本上,我想有一个自定义输入视图,用户可以用手指画出他/她的任何东西,在它下面,我想放置2个(或者更多)按钮,我不想在自定义视图的顶部重叠。因为我试图避免硬编码宽度和高度,有没有办法指定按钮应环绕到其内容,而自定义视图应占据剩余高度?因为我希望所有按钮都具有相同的高度,所以我想以其中一个按钮的高度作为参考应该会起到某种作用 以下是我当前的布局: <RelativeLayout xmlns:android="http://schemas.android
<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=".MainActivity" >
<com.example.myapp.DrawView
android:id="@+id/drawView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/save" />
<Button
android:id="@+id/buttonQuery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/query" />
</RelativeLayout>
是否真的可以轻松地实现我想要的,而不必用令人讨厌的方式进行破解?将自定义视图放置在
按钮上方
:
<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=".MainActivity" >
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/save" />
<Button
android:id="@+id/buttonQuery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/query" />
<com.example.myapp.DrawView
android:id="@+id/drawView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_above="@id/buttonSave" />
</RelativeLayout>
如果您不确定
按钮的高度是否相等,则必须将它们包装在另一个布局中(如线性布局),然后将自定义视图放置在该包装上方。将自定义视图放置在按钮上方:
<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=".MainActivity" >
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/save" />
<Button
android:id="@+id/buttonQuery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/query" />
<com.example.myapp.DrawView
android:id="@+id/drawView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_above="@id/buttonSave" />
</RelativeLayout>
如果您不确定按钮的高度是否相等,则必须将其包装在另一个布局中(如线性布局),然后将自定义视图放置在该包装上方。将按钮放置在某个布局上:
<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=".MainActivity" >
<com.example.myapp.DrawView
android:id="@+id/drawView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<RelativeLayout android:id="@+id/button_layout"
........
android:layout_alignParentBottom="true"
>
....
your buttons
.....
</RelativeLayout>
</RelativeLayout>
....
你的钮扣
.....
在某些布局上放置按钮:
<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=".MainActivity" >
<com.example.myapp.DrawView
android:id="@+id/drawView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<RelativeLayout android:id="@+id/button_layout"
........
android:layout_alignParentBottom="true"
>
....
your buttons
.....
</RelativeLayout>
</RelativeLayout>
....
你的钮扣
.....
但是如果我设置了android:layout\u height=“match\u parent”
,那么自定义视图将位于按钮下方,这正是我试图避免的…但是如果我设置了android:layout\u height=“match\u parent”
,那么自定义视图将位于按钮下方,这正是我试图避免的…酷家伙,成功了!如果可以的话,我会给你+10!:)如果要避免在DrawView@Mihai Todor前面声明按钮,可以在res/values/ids.xml
文件中声明这些ID。这样,您声明按钮/绘图视图的顺序就不再重要了。ID已经存在于布局文件的外部。酷伙计,这就成功了!如果可以的话,我会给你+10!:)如果要避免在DrawView@Mihai Todor前面声明按钮,可以在res/values/ids.xml
文件中声明这些ID。这样,您声明按钮/绘图视图的顺序就不再重要了。ID已存在于布局文件外部。