FrameLayout具有android:foreground、android:foregroundGravity和android:measureAllChildren属性。我尝试过这些属性,但无法弄清楚它们如何影响布局的外观或它们如何工作。
<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>我已经用谷歌搜索过了,但是找不到关于这些属性的帮助。请给我提供一个链接,我可以参考或帮助我举一个例子。谢谢
发布于 2016-01-27 04:31:54
android:foreground指向Framelayout需要在其所有子对象之上绘制的前景
android:foregroundGravity指出了该资产的重要性,如果该资产是可绘制的。这意味着如果您正在使用
android:foreground="@android:drawable/bottom_bar"然后,您的drawable将绘制在其所有子对象的顶部,并定位在Framelayout的中心
android:measureAllChildren :确定在测量时是测量所有子项,还是仅测量处于VISIBLE或INVISIBLE状态的子项。默认为false。这意味着,如果它被设置为false,那么当Framelayout的测量阶段运行时,GONE状态中的所有元素都不会被考虑在内。
希望这回答了你的问题。
发布于 2017-10-02 14:52:31
如果measureallchildren设置为"true“,那么它将显示框架布局的实际宽度和高度,即使视图的可见性处于消失状态。例如
<?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在屏幕上显示高度和宽度。
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
https://stackoverflow.com/questions/35022962
复制相似问题