当前位置: 代码迷 >> Android >> 怎样使两个按钮的位置成为左右并列而不覆盖?多谢
  详细解决方案

怎样使两个按钮的位置成为左右并列而不覆盖?多谢

热度:87   发布时间:2016-04-28 05:15:13.0
怎样使两个按钮的位置成为左右并列而不覆盖?谢谢!
 <Button
            android:id="@+id/previous_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/before" />


        <Button
            android:id="@+id/play_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
          
            android:background="@drawable/play" />
为什么这两个按钮中只能显示后一个呢?
------解决方案--------------------
你是直接用的线性布局,需要进行嵌套的
------解决方案--------------------
如果你用的线性布局,是可以不要这个的 android:layout_alignParentLeft="true"
------解决方案--------------------
你把所有的布局贴出来看看
------解决方案--------------------
  <Button
            android:id="@+id/play_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
          
            android:background="@drawable/play" />

这个button没有定位,必定无法显示。
------解决方案--------------------
你直接拖控件不就行了,,,
------解决方案--------------------
前一个被后一个挡住了。
1.使用线性布局
2.使用偏移   paddingLeft
3.第二个buton可以 android:layout_alignParentRight="true"
------解决方案--------------------
方法1:

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
<Button
            android:id="@+id/previous_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/before" />


        <Button
            android:id="@+id/play_music"
           <!--  注意这句-->
            android:layout_toRightOf="@+id//previous_music" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
          
            android:background="@drawable/play" />

</RelativeLayout>
------解决方案--------------------
方法2:
<LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
<Button
            android:id="@+id/previous_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/before" />


        <Button
            android:id="@+id/play_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
  相关解决方案