首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >FrameLayout中的“android:foreground”和“android:foreground”对外观有什么影响?

FrameLayout中的“android:foreground”和“android:foreground”对外观有什么影响?
EN

Stack Overflow用户
提问于 2016-01-27 04:09:30
回答 2查看 24K关注 0票数 12

FrameLayout具有android:foregroundandroid:foregroundGravityandroid:measureAllChildren属性。我尝试过这些属性,但无法弄清楚它们如何影响布局的外观或它们如何工作。

代码语言:javascript
运行
复制
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:foreground="@android:color/holo_blue_dark"
 android:foregroundGravity="center"
 android:measureAllChildren="true"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.example.framelayoutdemo.MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@android:drawable/btn_dialog" />

</FrameLayout>

我已经用谷歌搜索过了,但是找不到关于这些属性的帮助。请给我提供一个链接,我可以参考或帮助我举一个例子。谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-27 04:31:54

android:foreground指向Framelayout需要在其所有子对象之上绘制的前景

android:foregroundGravity指出了该资产的重要性,如果该资产是可绘制的。这意味着如果您正在使用

代码语言:javascript
运行
复制
android:foreground="@android:drawable/bottom_bar"

然后,您的drawable将绘制在其所有子对象的顶部,并定位在Framelayout的中心

android:measureAllChildren :确定在测量时是测量所有子项,还是仅测量处于VISIBLEINVISIBLE状态的子项。默认为false。这意味着,如果它被设置为false,那么当Framelayout的测量阶段运行时,GONE状态中的所有元素都不会被考虑在内。

希望这回答了你的问题。

票数 17
EN

Stack Overflow用户

发布于 2017-10-02 14:52:31

如果measureallchildren设置为"true“,那么它将显示框架布局的实际宽度和高度,即使视图的可见性处于消失状态。例如

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/myframe"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:measureAllChildren="true"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:src="@drawable/ic_launcher"/>

</FrameLayout>

下面是MainActivity.java的代码。如果我们使用Toast在屏幕上显示高度和宽度。

代码语言:javascript
运行
复制
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myframe_activity);
        FrameLayout frame=(FrameLayout)findViewById(R.id.frame);
        frame.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int width = frame.getMeasuredWidth();
        int height = frame.getMeasuredHeight();
        Toast.makeText(getApplicationContext(),"width="+width+"  height="+height,Toast.LENGTH_SHORT).show();

    }

}

如果我们在模拟器中运行应用程序,Toast消息形式的输出将如下所示: width=72 height=72

现在,如果我们将measureAllChildren的值更改为false,那么Toast message输出的frame layout宽度和高度将是: width=0 height=0

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35022962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档