Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了右侧带有视图的Android布局,占据预设空间,左侧视图可以将屏幕的其余部分填充到一定的限制大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Android中制作了一个布局(XML文件),它有两个子视图(一个位于屏幕右侧,另一个位于左侧).我希望右边的视图占据一个预定的空间(在dp中)并让左边的视图占用所有剩余的空间达到极限,此时它将停止扩展,这两个布局将只是随着屏幕变大,进一步分开.

奇怪的是,如果我希望右侧的视图是扩展的视图,并且左侧的视图是占用预设空间的视图,这将非常容易.如果您将每个视图设置为所需的宽度(在水平线性布局中),如果两个视图都不适合,Android将自动缩小左侧的视图.

我想在一个布局文件中执行此操作;这种布局已经设计用于sw512dp-land和sw765dp-land之间的显示.

如果我能找到一种方法让Android缩小左侧的布局(当布局都不能适合指定的大小时),下面的代码就可以工作了.但认情况下,系统会先缩小右侧的布局.

<LinearLayout xmlns:android="http://scheR_434_11845@as.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<RelativeLayout
    android:id="@+id/left"
    android:layout_width="150dip"
    android:layout_height="fill_parent"
    android:BACkground="@color/red" >
</RelativeLayout>

<LinearLayout
    android:id="@+id/right"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:layout_alignParentright="true"
    android:layout_alignParentTop="true"
    android:BACkground="@color/green" >
</LinearLayout>

如果我不需要左边的布局来停止某个点的扩展,那么这个代码(来自@Lokesh)就可以工作了.

<RelativeLayout xmlns:android="http://scheR_434_11845@as.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<LinearLayout
    android:id="@+id/left"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_toLeftOf="@+id/right"
    android:BACkground="@color/red" >

</LinearLayout>

<LinearLayout
    android:id="@+id/right"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:layout_alignParentright="true"
    android:layout_alignParentTop="true"
    android:BACkground="@color/green" >
</LinearLayout>

如果有人认为这是不可能的,那么我也可以采取实际操作或改变我的布局方法.

谢谢!

解决方法

这适合我.我已将正确的布局设置为100dip,根据您的需要进行更改.
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://scheR_434_11845@as.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/left"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@+id/right"
        android:BACkground="@color/red" >

    </LinearLayout>

    <LinearLayout
        android:id="@+id/right"
        android:layout_width="100dip"
        android:layout_height="fill_parent"
        android:layout_alignParentright="true"
        android:layout_alignParentTop="true"
        android:BACkground="@color/green" >
    </LinearLayout>

</RelativeLayout>

编辑1:我使用背景颜色只是为了清楚地显示布局.根本没必要.

本图文内容来源于网友网络收集整理提供,作为学习参使用,版权属于原作者。

大佬总结

以上是大佬教程为你收集整理的右侧带有视图的Android布局,占据预设空间,左侧视图可以将屏幕的其余部分填充到一定的限制全部内容,希望文章能够帮你解决右侧带有视图的Android布局,占据预设空间,左侧视图可以将屏幕的其余部分填充到一定的限制所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。