2012-03-21 40 views
1

我已经为我的应用程序创建了仪表板。在那我也添加了搜索按钮。我希望将此按钮对齐到右侧,但为此我不想使用边距。我添加了我的布局+代码的图像。在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> 

OLD

NEW UPDATED

更新我的代码,只需一步即可完成。分离器是一些不可见的。

如果有人有任何想法,请帮助我。

谢谢

回答

2

尝试

<ImageButton 
     style="@style/TitleBarAction" 
     android:contentDescription="Searching..." 
     android:onClick="onClickSearch" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/title_search" /> 
+0

感谢您的回复。我试过这个,但结果仍然一样。而且layout_alignParentRight也没有建议.... – Prem 2012-03-21 16:40:45

+1

使用RelativeLayout来代替LinearLayout – 2012-03-21 16:51:24

+0

实际上我也尝试过使用相对布局。但是当我使用它时,所有的事情都在这里和那里。我正在研究相对布局。如果您有任何建议,请让我知道。我在这里发布了整个仪表板布局。 – Prem 2012-03-21 17:17:43

1

虽然我会建议考虑使用Action Bar如果可能的话,

android:layout_alignParentRight="true" 

应该工作,你也可以acheive你想要什么使您的TitleBarLogo和放大镜图形a 9-patch image离开中间空白,并自动调整大小,无di放置图形。

+1

我已经添加了我的styles.xml代码。而我尝试layout_alignParentRight =“true”但不工作。 – Prem 2012-03-21 16:42:54

+0

除了'ImageView'中的'alignParentRight'你看过http://stackoverflow.com/questions/655994/android-layout-alignment-issue-with-imageview? 'android:scaleType =“fitStart”' – TryTryAgain 2012-03-21 16:51:19

+0

我在我的ImagaButton中添加了alignParentRight .. – Prem 2012-03-21 16:52:42