本人菜鸟,刚刚开始学着写第一个android app 遇到一个也许是很菜的问题,但是被纠结了一天都没搞出来,麻烦大神指点下。
我的目的是想让home 和favorite 两个按钮居中,play按钮靠右,但是试了好多办法都调不到我想要的位置上。
界面截图:
代码如下:
<LinearLayout 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"
android:background="@drawable/background"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@drawable/nav_bar_background_img_2x"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/nav_main_selected_2x" />
<Button
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/nav_favorite_2x" />
</LinearLayout>
<Button
android:id="@+id/playlist"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:background="@drawable/popview_playbtn_2x" />
</LinearLayout>
<com.org.happyenglish.service.list.ItemListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout 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"
android:background="@drawable/background"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@drawable/nav_bar_background_img_2x" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/nav_main_selected_2x" />
<Button
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/nav_favorite_2x" />
</LinearLayout>
<Button
android:id="@+id/playlist"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:background="@drawable/popview_playbtn_2x" />
</FrameLayout>
<com.org.happyenglish.service.list.ItemListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout 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"
android:background="@drawable/background"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@drawable/nav_bar_background_img_2x"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<Button
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/nav_main_selected_2x" />
<Button
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/nav_favorite_2x" />
</LinearLayout>
<Button
android:id="@+id/playlist"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="@drawable/popview_playbtn_2x" />
</RelativeLayout>
<com.org.happyenglish.service.list.ItemListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
像这种布局最后用relativelayout好控制,你看看吧,吧里面的图片改成自己的图片
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<!-- id为title是上面的整个标题,用RelativeLayout好控制 -->
<RelativeLayout
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFF0000"
android:orientation="horizontal" >
<!-- 这个控制中间的那一块 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#FF00FF00" >
<Button
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/ic_launcher" />
<Button
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher" />
</LinearLayout>
<!-- 最右面 -->
<Button
android:id="@+id/playlist"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="@drawable/ic_launcher" />
</RelativeLayout>
<com.org.happyenglish.service.list.ItemListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />