【问题标题】:Need help in Dashboard in Android在 Android 的仪表板中需要帮助
【发布时间】:2012-04-06 05:05:52
【问题描述】:

我为我的应用创建了仪表板。在那我也添加了搜索按钮。我希望将此按钮对齐到右侧,但为此我不想使用边距。我添加了我的布局 + 代码的图像。

更新

<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>

更新了我的代码,只需一步即可完成。分隔符有些不可见。

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

谢谢

【问题讨论】:

    标签: android android-layout dashboard


    【解决方案1】:

    试试

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

    【讨论】:

    • 感谢您的回复。我试过了,但结果还是一样。也不建议使用 layout_alignParentRight....
    • 使用RelativeLayout代替LinearLayout
    • 实际上我也尝试过相对布局。但是当我使用它时,一切都只是在这里和那里。我正在研究相对布局。如果您对此有任何建议,请告诉我。我已经在这里发布了整个仪表板布局。
    • 请看我的更新代码。我使用了RelativeLayout,几乎实现了我的愿望。只有分隔符不可见。如果您有任何想法,请告诉我。
    【解决方案2】:

    尽管我建议尽可能使用Action Bar

    android:layout_alignParentRight="true"
    

    应该可以,您还可以通过将您设置为TitleBarLogo 和放大镜图形a 9-patch image 来实现您想要的效果,这会使中间留空并自动调整大小而不会扭曲图形。

    【讨论】:

    • 我已经添加了我的 styles.xml 代码。我尝试 layout_alignParentRight="true" 但不工作。
    • 除了alignParentRight中的ImageView,你见过stackoverflow.com/questions/655994/…吗? android:scaleType="fitStart"
    • 对不起,我正在编辑上面的评论。正如appserv所说,我建议使用RelativeLayout而不是LinearLayout,然后你可以使用android:gravity="right"这里是一个例子groups.google.com/forum/?fromgroups#!topic/android-beginners/…
    • @Prem for RelativeLayout 只需将所有LinearLayout 替换为RelativeLayout,然后在ImageButton 中尝试android:gravity="right"
    • 我已经使用了RelativeLayout,我几乎可以实现它。分隔符有些不可见。请看我更新的代码...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多