Android布局重量不适用于相对布局

Android布局重量不适用于相对布局,第1张

概述嘿伙计们我自己第一次尝试实现布局重量,有点我尝试使用线性布局它运行良好,但是当我尝试使用相对和线性布局时出现问题.你们可以告诉我这里有什么问题吗 我的XML文件 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android 嘿伙计们我自己第一次尝试实现布局重量,有点我尝试使用线性布局它运行良好,但是当我尝试使用相对和线性布局时出现问题.你们可以告诉我这里有什么问题吗

我的XML文件

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:ID="@+ID/linearlayout"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:orIEntation="vertical"androID:weightSum="100" ><relativeLayout    androID:ID="@+ID/Rlayout"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:layout_weight="45" >    <gallery        androID:ID="@+ID/gallery01"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:spacing="4dip" >    </gallery></relativeLayout><relativeLayout    androID:ID="@+ID/Rlayout1"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:layout_weight="10"    androID:orIEntation="vertical" >    <ImageVIEw        androID:ID="@+ID/ImageVIEw01"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:scaleType="fitXY" />    <ImageVIEw        androID:ID="@+ID/ImageVIEw02"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:scaleType="fitXY" /></relativeLayout><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/navbar"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:layout_weight="45"    androID:background="@drawable/button1"    androID:orIEntation="horizontal"    androID:weightSum="100" >    <button        androID:ID="@+ID/makerback"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:layout_gravity="center"        androID:layout_weight="20"        androID:background="@drawable/makerback" />    <button        androID:ID="@+ID/makerphoto"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:layout_gravity="center"        androID:layout_weight="20"        androID:background="@drawable/makerphoto" />    <button        androID:ID="@+ID/makerselves"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:layout_gravity="center"        androID:layout_weight="20"        androID:background="@drawable/makerselves" />    <button        androID:ID="@+ID/makerskins"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:layout_gravity="center"        androID:layout_weight="20"        androID:background="@drawable/makerskins" />    <button        androID:ID="@+ID/makersave"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:layout_gravity="center"        androID:layout_weight="20"        androID:background="@drawable/makersave" /></linearLayout></linearLayout>

我需要实现上面的图像

解决方法

You cannot use percentages to define the dimensions of a VIEw insIDe a
relativeLayout. The best ways to do it is to use linearLayout and
weights,or a custom Layout.
-Romain Guy

Percentage width in a RelativeLayout

来自Docs:http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#weight

UPDATE

我们现在可以使用PercentRelativeLayout.来自docs的示例:

<androID.support.percent.PercentrelativeLayout    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">    <ImageVIEw        app:layout_wIDthPercent="50%"        app:layout_heightPercent="50%"        app:layout_margintopPercent="25%"        app:layout_marginleftPercent="25%" /></androID.support.percent.PercentFrameLayout>
总结

以上是内存溢出为你收集整理的Android布局重量不适用于相对布局全部内容,希望文章能够帮你解决Android布局重量不适用于相对布局所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1137461.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存