标签: android-layout-weight

布局重量问题

这一直让我发疯,我已尝试过其他帖子的各种帮助(设置宽度为0dp等),但似乎没有任何效果.

我有2个布局,第一个仍然似乎占主导地位:/.如果我在文本视图中添加背景颜色,它们会表现自己并正确结束.然而,在线性布局上放置背景,它几乎是屏幕的3/4!?

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:id="@+id/rowkRow"
    android:background="@color/RowBkgColor" android:gravity="center_vertical"
    android:minHeight="60dp">
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/rowleftImage"
        android:padding="3dip" android:gravity="left" android:layout_weight="0" />

    <LinearLayout android:orientation="vertical"
        android:layout_weight="0" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/rowtext1"
            android:padding="3dip" android:gravity="left" android:typeface="sans"
            android:textStyle="bold" android:text="First Text" android:textSize="40dp"
            android:textColor="#FF333344" android:visibility="visible" 
             />
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/rowtext3"
            android:padding="3dip" android:gravity="center" android:typeface="sans"
            android:textStyle="bold" android:text="First Text" android:textSize="10dp"
            android:textColor="#FF333344" android:visibility="visible"
            android:background="#606060"
             />
    </LinearLayout>

    <LinearLayout android:orientation="vertical"
        android:layout_weight="1" android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/rowtext4"
            android:padding="3dip" android:gravity="right" android:text="Fourth Text"
            android:textSize="10dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
            android:visibility="visible" />
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/rowtext2"
            android:padding="3dip" android:gravity="left" android:text="Second …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-layout-weight

1
推荐指数
1
解决办法
2793
查看次数

固定屏幕上的布局比例

在我的应用程序中,我有2个线性布局:一个在顶部,一个在底部.

我希望无论这些布局如何,顶部的布局占据屏幕高度的60%,底部布局占40%.这是我的XML代码:

   <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_weight="1.0" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.6"
        android:orientation="vertical" 
         android:id="@+id/layout_top">
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="0.4" 
        android:id="@+id/layout_bottom">
    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

当这些布局是空的,没有问题时,它们具有良好的比例.

问题是,如果我在顶部布局中放置一个小的列表视图,那么布局将采用列表视图的大小,并且不会保留60/40%的比例.

即使我的列表视图很小(例如只有3项),我也会喜欢它,布局保留了60%,所以在我的listview下放了一些空白区域.

我试着寿变化android:layout_heightmatch_parent,但它不会改变任何东西.

谢谢.

android percentage android-layout android-view android-layout-weight

1
推荐指数
1
解决办法
2875
查看次数

嵌套权重对我的XML代码的性能不利

我想显示一个有组织的网格.所以我使用LinearLayout和Layout Weight选项,每件事情都很完美,但我不明白如何在按钮A和按钮C中避免这个警告:

Nested weights are bad for performance
Run Code Online (Sandbox Code Playgroud)

这是我的XML代码:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <!-- First row. -->

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

            <Button
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="A" />

            <Button
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:text="B" />
        </LinearLayout>

        <!-- Second row. -->

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

            <Button
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:text="C" />

            <Button
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:text="D" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我该如何避免这个错误?

xml android android-layout-weight

1
推荐指数
1
解决办法
1万
查看次数

Android 布局权重不起作用

我得到了这个布局:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="6sp"
    android:layout_marginLeft="16sp"
    android:layout_marginRight="6sp"
    android:layout_marginTop="6sp" >

    <TextView android:id="@+android:id/title"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceListItem"
        android:inputType="none" />

    <TextView android:id="@+android:id/summary"
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_below="@android:id/title" 
        android:maxLines="2"
        android:layout_width="wrap_content" />

</RelativeLayout>

<!-- Preference should place its actual preference widget here. -->
<!-- android:id="@android:id/widget_frame" -->

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="6sp"
    android:layout_marginLeft="6sp"
    android:layout_marginRight="6sp"
    android:layout_marginTop="10sp"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:weightSum="1" >

    <SeekBar
        android:id="@+id/change_seekbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.8"
        android:paddingLeft="20dip"
        android:paddingRight="20dip" >

    </SeekBar>

    <TextView
        android:id="@+id/Text_Box_seek"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:textSize="16dip" >
    </TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我希望搜索栏占据内部线性布局中宽度的 80%,但搜索栏仍然很小..为什么它不占据其余空间?

android android-layout android-layout-weight

1
推荐指数
1
解决办法
1356
查看次数

在 ConstraintLayout 中,当没有 `weight` 属性时, android:layout_width="0dp" 是什么意思?

我有这样的布局:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlayGoogleMaterialIcons">

  <LinearLayout
      android:layout_height="wrap_content"
      android:layout_width="0dp">

...
Run Code Online (Sandbox Code Playgroud)

android:layout_width="0dp"不属于 的孩子 是什么意思LinearLayout

android:layout_width="0dp"没有属性的时候是什么意思weight

android android-layout-weight android-constraintlayout

1
推荐指数
1
解决办法
5481
查看次数

Android软键盘隐藏带有windowSoftInputMode设置的编辑文本字段

我的一些活动由3个垂直布局的片段组成(顶部,中间和底部)

中间片段是包装在滚动视图中的唯一片段。顶部和底部片段是静态的。底部片段具有用于用户输入的编辑文本控件。从上到下的片段权重分别为.1,.6和.3

当出现软键盘以供用户输入时,软键盘将覆盖用户需要在其中输入文本的编辑文本字段。似乎碎片向上移动,但不够用,底部碎片的一半被键盘覆盖了。我使用了多个带有windowSoftInputMode属性的开关,但似乎没有一个起作用。

windowSoftInputMode =“ adjustResize | stateHidden” windowSoftInputMode =“ adjustPan”

显示软键盘时,如何保证至少底部片段是完全可见的?我需要做什么?

android android-softkeyboard android-fragments android-layout-weight

0
推荐指数
1
解决办法
4427
查看次数

线性布局匹配父级或权重在协调器布局中不起作用

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.now.sexyfacechanger.Activity_PhotoOrGallery">

    <include layout="@layout/content_activity__photo_or_gallery" />

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

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_camera"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_weight="1"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_gallery"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_weight="1"/>

    </LinearLayout>


</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是android studio设计中的视图,显示的线性布局与父级匹配:

在此处输入图片说明

但是输出:

在此处输入图片说明

线性布局与父布局不匹配,或者我怀疑应用于两个浮动按钮的 layout_weight 在协调器布局中不起作用。

android android-linearlayout android-layout-weight android-coordinatorlayout android-layoutparams

0
推荐指数
1
解决办法
1904
查看次数

android:background not reflected in view with layout weight

我有一个简单LinearLayoutImageView布局视图,法线视图的权重分别为0.55和0.45。

除非我给weightsum我的礼物,我不能分手LinearLayout

有我的后LinearLayout裂开,我试图给一个背景色,以我的看法,但它不是反映。

下面是我的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1"
    >
    <ImageView
        android:layout_weight=".55"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="5dip"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher_background"
        android:contentDescription="TODO" />

    <View
        android:layout_weight=".45dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:visibility="visible"
        android:background="@color/colorPrimary"
        ></View>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我不知道应该进行哪些更改,以便可以正确拆分视图并设置背景颜色。提前致谢!

android android-linearlayout android-background android-layout-weight

0
推荐指数
1
解决办法
40
查看次数

WeightSum 在 android 的 LinearLayout 中没有按预期工作

好吧,我有一个带有两个孩子的 LinearLayout,一个 EditText 和一个 Button,它们的weightSum都是3. 我想要的只是一条带有2layout_weight EditText 和1layout_weight Button的水平线。这是我的代码:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:weightSum="3">

    <EditText
        android:id="@+id/edit1"
        android:inputType="textAutoComplete"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/DBLocations"
        android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但是权重不起作用,结果如下: 错误结果的屏幕截图 为了2在 EditText 和1Button 中拥有layout_weight我必须做什么?

android android-layout-weight

-1
推荐指数
1
解决办法
1731
查看次数