简体   繁体   English

Android:LinearView左右固定大小的小部件,中间是灵活的小部件

[英]Android: LinearView with fixed sized widgets left and right and a flexible one in the middle

Seems to be a simple question, but I can't figure out how to do it. 似乎是一个简单的问题,但我无法弄清楚如何做到这一点。

I have a horizontal LinearView with something of fixed size at the left, then comes some text which should take as mich space as possible, but on the right should be another fixed-size object. 我有一个水平的LinearView,在左边有一些固定大小的东西,然后是一些文本应该尽可能地作为mich空间,但在右边应该是另一个固定大小的对象。

Now, my problems are right now: When the text in the middle is too long, the object at the right gets pushed out of the window. 现在,我的问题是现在:当中间的文本太长时,右边的对象被推出窗口。 When the text is too short, it does not sit at the right border of the window, but directly next to the text. 当文本太短时,它不会位于窗口的右边界,而是直接位于文本旁边。

How can I do it? 我该怎么做? My Code so far (As you can see, I tried to use the LayoutWeight, which didn't help...): 到目前为止我的代码(正如你所看到的,我试图使用LayoutWeight,这没有帮助......):

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

    <TextView
        android:id="@+id/important"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="10dp"
        android:background="#000000"
        android:layout_weight="1"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="5dp"
            android:paddingRight="5dp"
            android:paddingLeft="0dp"
            android:textColor="#333333"
            android:paddingBottom="0dp"
            android:textSize="14sp"
            android:scrollHorizontally="true"/>
        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#666666"
            android:paddingTop="3dp"
            android:paddingRight="5dp"
            android:paddingLeft="10dp"
            android:paddingBottom="5dp"
            android:textSize="12sp" />
    </LinearLayout>

    <ImageView android:id="@+id/lastpage" 
        android:src="@drawable/lastpage"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="200"
        android:scaleType="center"
        android:layout_gravity="right"/>
</LinearLayout>

You have android:layout_weight="1" on two widgets (first and second children of the LinearLayout ), which does not match your business rules. 您在两个小部件( LinearLayout第一个和第二LinearLayout )上有android:layout_weight="1" ,这与您的业务规则不匹配。

Personally, I would use a RelativeLayout here. 就个人而言,我会在这里使用RelativeLayout Use android:layout_alignParentLeft="true" on the first child, android:layout_alignParentRight="true" on the third child, and android:toLeftOf and android:toRightOf on the middle, anchoring it between the outer fixed children. 在第一个孩子上使用android:layout_alignParentRight="true" ,在第三个孩子上使用android:layout_alignParentLeft="true" ,在中间使用android:toLeftOfandroid:toRightOf ,将其锚定在外部固定子项之间。 That more explicitly implements your desired business rules. 这更明确地实现了您期望的业务规则。

Looking at this answer Android: LinearView with fixed sized widgets left and right and a flexible one in the middle you maybe just need to set the layout_width of your middle element to 0px to make it not use the width gained by content but decide about it via the weight. 看看这个答案Android:LinearView左右固定大小的小部件和中间的灵活小部件你可能只需要将中间元素的layout_width设置为0px,使其不使用内容获得的宽度,而是通过重量。

Hope this helps. 希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 小部件固定大小的图标Android - Widget fixed sized icon Android 在 Android 中,我有 2 个按钮和一个文本。 我必须向左排列一个按钮,中间放置文本,右侧放置一个按钮。 我怎样才能做到这一点? - In Android, I am having 2 Buttons and one Text. I have to arrange one button left, Text in Middle, and One Button in Right. How can I do this? 安卓; 如何在其他小部件保持左对齐时右对齐按钮 - Android; How to Right Justify Buttons while other widgets stay Left Justified 如何从左到右为Android一一制作图像 - How to animate images one by one from left to right android Android布局:左一,右一,中一? - Android layout: one on left, one on right, one on center? 如何在android中居中固定大小的主要布局? - How to center a fixed sized main layout in android? Android:如何通过单击一个按钮从右到左,左右移动选取框文本 - Android:how to move marquee text from right to left and left and right by clicking one button Android LinearLayout以编程方式向左移一列,向右浮动一列 - Android LinearLayout programmatically one column left, one column float right 如何在Android中实现自定义图片库,在左右两端显示一半图像,在中间显示完整图像? - How to implement custom gallery in Android with half images being displayed on right and left end and a full image in the middle? 在android中从左向右和从右向左滑动 - swipe from left to right and right to left in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM