我已经为我的应用程序创建了仪表板。在那我也添加了搜索按钮。我希望将此按钮对齐到右侧,但为此我不想使用边距。我添加了我的布局+代码的图像。在Android中的仪表板需要帮助
修订
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout style="@style/TitleBar" >
<ImageView
android:id="@+id/logo"
style="@style/TitleBarLogo"
android:layout_toRightOf="@id/titlebar"
android:contentDescription="Logo"
android:src="@drawable/logo" />
<ImageView
style="@style/TitleBarSeparator"
android:layout_toRightOf="@id/logo"
android:visibility="visible" />
<ImageButton
style="@style/TitleBarAction"
android:layout_alignParentRight="true"
android:contentDescription="Searching..."
android:onClick="onClickSearch"
android:src="@drawable/title_search" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/titlebar"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:orientation="horizontal" >
<Button
android:id="@+id/home_btn_feature1"
style="@style/HomeButton"
android:drawableTop="@drawable/home_button1"/>
<Button
android:id="@+id/home_btn_feature2"
style="@style/HomeButton"
android:drawableTop="@drawable/home_button2"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
android:orientation="horizontal" >
<Button
android:id="@+id/home_btn_feature3"
style="@style/HomeButton"
android:drawableTop="@drawable/home_button3"/>
<Button
android:id="@+id/home_btn_feature4"
style="@style/HomeButton"
android:drawableTop="@drawable/home_button4"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
修订
styles.xml
<style name="TitleBar">
<item name="android:id">@id/titlebar</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_background</item>
</style>
<style name="TitleBarLogo">
<item name="android:id">@id/title_logo</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:clickable">true</item>
</style>
<style name="TitleBarAction">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/title_button</item>
</style>
<style name="TitleBarSeparator">
<item name="android:layout_width">1px</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@color/title_separator</item>
</style>
更新我的代码,只需一步即可完成。分离器是一些不可见的。
如果有人有任何想法,请帮助我。
谢谢
感谢您的回复。我试过这个,但结果仍然一样。而且layout_alignParentRight也没有建议.... – Prem 2012-03-21 16:40:45
使用RelativeLayout来代替LinearLayout – 2012-03-21 16:51:24
实际上我也尝试过使用相对布局。但是当我使用它时,所有的事情都在这里和那里。我正在研究相对布局。如果您有任何建议,请让我知道。我在这里发布了整个仪表板布局。 – Prem 2012-03-21 17:17:43