layout_margintop 百分比_layout marginleft_layout marginend用法(2)

电脑杂谈  发布时间:2017-04-11 11:24:14  来源:网络整理

效果如下:

完美.

支持的属性:

layout_widthPercent

layout_heightPercent

layout_marginPercent

layout_marginLeftPercent

layout_marginTopPercent

layout_marginRightPercent

layout_marginBottomPercent

layout_marginStartPercent

layout_marginEndPercent

layout_aspectRatio

It is not necessary to specify layout_width/height if you specify layout_widthPercent. However, if you want the view to be able to take up more space than what percentage value permits, you can add layout_width/height=”wrap_content”. In that case if the percentage size is too small for the View’s content, it will be resized using wrap_content rule.

layout marginend用法_layout_margintop 百分比_layout marginleft

如果指定了layout_widthPercent就不用指定layout_width/height属性了。(Studio可能会提示错误,设置忽略就好)。然而,如果你想要该View能够占用比设置的百分比值更大的空间时,你可以指定layout_widht/height=“wrap_content”。在这种情况下,如果设置的百分比值在显示内容时太小时,将会使用wrap_content的值重新计算。

就是这个意思:如果指定的百分比太小怕显示不开的话,也可以给它指定wrap_content属性,这样当显示不开的时候就会使用wrap_content的值。

如下:

<android.support.percent.PercentFrameLayout
    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">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        android:text="顶顶顶顶顶大大大"
        android:textSize="30dp"
        android:singleLine="true"
        app:layout_widthPercent="30%"
        app:layout_heightPercent="5%"
        app:layout_marginTopPercent="25%"
        app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentFrameLayout>


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-40673-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...