应用程序运行时,Android布局设计不一样

时间:2017-05-17 10:50:48

标签: android layout

我的布局设计在Android Studio预览和正在运行的应用中并不相同:

设计正在运行的应用

enter image description here

预期设计

enter image description here

这是XML文件:

const css = `
        .hover-list a:hover {
        color: #F89800;
    }
`

<div className="hover-list">
    <Navbar.Collapse>
          <Nav pullRight>
            <NavItem eventKey={1} href="#">1</NavItem>
            <NavItem eventKey={2} href="#">2</NavItem>
            <NavItem eventKey={3} href="#" className="my-class">3</NavItem>
          </Nav>
    </Navbar.Collapse>
</div>

你知道发生了什么吗?

提前感谢您的帮助

3 个答案:

答案 0 :(得分:1)

您应该使用android:weightSum代替。{  内心android:layout_weight LinearLayout
您还应该在使用android:layout_width="0dp"

时为孩子添加weightSum
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="2">

        <Button
            android:text="Manage messages"
            android:layout_width="0dp"
           android:layout_height="wrap_content"
            android:id="@+id/bt_messages"
            android:drawableLeft="@mipmap/ic_message"
            android:layout_weight="1" />

        <Button
            android:text="Manage activities"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/bt_activities"
            android:drawableLeft="@mipmap/ic_activities"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>

答案 1 :(得分:1)

你可以这样做

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:text="Manage messages"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/bt_messages"
        android:drawableLeft="@mipmap/ic_message"
        android:layout_weight="1" />

    <Button
        android:text="Manage activities"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/bt_activities"
        android:drawableLeft="@mipmap/ic_activities"
        android:layout_weight="1" />
</LinearLayout>

答案 2 :(得分:0)

你可以试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1">

        <Button
            android:text="Manage messages"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt_messages"
            android:drawableLeft="@mipmap/ic_message"
            android:layout_weight=".5" />

        <Button
            android:text="Manage activities"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt_activities"
            android:drawableLeft="@mipmap/ic_activities"
            android:layout_weight=".5" />
    </LinearLayout>

</LinearLayout>