Tag: android layout

fitsSystemWindows究竟做了什么?

我正在努力理解fitsSystemWindows的概念,因为它依赖于视图执行不同的事情。 根据官方文件,这是一个 布尔型内部属性可根据系统窗口(如状态栏)调整视图布局。 如果为true,则调整此视图的填充以为系统窗口留出空间 。 现在,检查View.java类,我可以看到,当设置为true ,窗口插件(状态栏,导航栏…)被应用到视图填充,根据上面引用的文档工作。 这是代码的相关部分: private boolean fitSystemWindowsInt(Rect insets) { if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { mUserPaddingStart = UNDEFINED_PADDING; mUserPaddingEnd = UNDEFINED_PADDING; Rect localInsets = sThreadLocal.get(); if (localInsets == null) { localInsets = new Rect(); sThreadLocal.set(localInsets); } boolean res = computeFitSystemWindows(insets, localInsets); mUserPaddingLeftInitial = localInsets.left; mUserPaddingRightInitial = localInsets.right; internalSetPadding(localInsets.left, localInsets.top, localInsets.right, […]

如何将填充分配给Listview项目分隔线

我如何给填充列表项目,因为我在图像中显示。 我想在图像中显示布局中的分隔线。 这是我的列表片段代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="25dp" android:layout_marginRight="25dp"> <ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/listV_main" android:layout_marginLeft="25dp" android:layout_marginRight="25dp"/> 这是我的列表部分代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="10dp" android:paddingTop="10dp" android:paddingRight="10dp" android:paddingBottom="10dp"> <include android:id="@+id/list_item_section_text" layout="@android:layout/preference_category" /> 这是我的列表项目代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:adjustViewBounds="true" android:paddingRight="?android:attr/scrollbarSize" > <ImageView android:id="@+id/showlist_item_entry_drawable" android:layout_width="82dp" android:adjustViewBounds="true" android:layout_height="68dp" android:scaleType="fitXY" android:paddingLeft="9dp"/> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="6dip" android:layout_marginTop="6dip" android:layout_marginBottom="6dip" android:layout_weight="1" > […]

LinearLayout vs RelativeLayout

Android中的RelativeLayout比LinearLayout有什么优势? 对于一个你更喜欢的特定devise,背后的原因是什么? 它是(RelativeLayout)相似或类似的HTML <div> ?

获取视图的边缘

我怎样才能从一个活动获得视图的保证金值? 视图可以是任何types的。 经过一番search后,我find了一种方法来获得一个视图的填充,但无法find任何保证金。 谁能帮忙? 我尝试了这样的事情 ViewGroup.LayoutParams vlp = view.getLayoutParams(); int marginBottom = ((LinearLayout.LayoutParams) vlp).bottomMargin; 这工作,但在上面的代码中,我已经认为是一个LinearLayout视图。 但是,即使我不知道视图types,我也需要获得margin属性。

Android的边缘开始/结束和右/左之间有什么区别?

Android保证金开始和权利(或保证金结束和左侧)有什么区别? 这是一个微不足道的问题,但我似乎无法从文档中了解视图的开始/结束和左/右之间的区别。 这可能是我不明白的地方,但是我根本无法取得任何进展。

自己定义的Layout,onDraw()方法没有被调用

我定义了这样一个类: public class TestMyFrameLayout extends FrameLayout{ Paint mPaint; public TestMyFrameLayout(Context context, AttributeSet attrs) { super(context, attrs); } public TestMyFrameLayout(Context context) { super(context); mPaint = new Paint(); mPaint.setColor(Color.GREEN); } protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(50f, 50f, 30, mPaint); } } 并称之为: TestMyFrameLayout myFrameLayout = new TestMyFrameLayout(this); LayoutParams myFrameLayoutParams = new LayoutParams(300,300); myFrameLayout.setLayoutParams(myFrameLayoutParams); setContentView(myFrameLayout); 但是实际上TestMyFrameLayout.onDraw(Canvas canvas)函数没有被调用,为什么呢?

FrameLayout边距不起作用

我的布局结构是这样的 LinearLayout FrameLayout ImageView ImageView FrameLayout TextView LinearLayout 我为FrameLayout中的两个ImageView设置了margin。 但是FrameLayout页边距被丢弃,并且它总是将图像设置在左上angular。 如果我从FrameLayout更改为LinearLayout边距的工作正常。 如何处理这个? <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/inner1" > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:layout_width="24px" android:layout_height="24px" android:id="@+id/favicon" android:layout_marginLeft="50px" android:layout_marginTop="50px" android:layout_marginBottom="40px" android:layout_marginRight="70px" /> <ImageView android:layout_width="52px" android:layout_height="52px" android:id="@+id/applefavicon" android:layout_marginLeft="100px" android:layout_marginTop="100px" android:layout_marginBottom="100px" android:layout_marginRight="100px" /> </FrameLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:layout_marginLeft="10px" android:layout_marginTop="20px" android:textColor="#FFFFFF" android:textSize = […]

如何将内容置于线性布局中?

我试图在一个LinearLayout水平和垂直中心的ImageView ,但我不能做到这一点。 为什么我不使用RelativeLayout主要原因是因为我需要layout_weight (我的Activity由四列组成,这四列应该平分,同时也响应不同的屏幕宽度,每列有一个ImageView居中和非拉伸)。 这是我的xml到目前为止: <LinearLayout 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:background="#000" android:baselineAligned="false" android:gravity="center" 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=".Main" > <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" > <ImageView android:id="@+id/imageButton_speak" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/image_bg" android:src="@drawable/ic_speak" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" > <ImageView android:id="@+id/imageButton_readtext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/image_bg" android:src="@drawable/ic_readtext" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" > <ImageView android:id="@+id/imageButton_edit" […]

Android:使用animation显示/隐藏视图

我一直在浏览很多谷歌的结果/问题,以确定如何通过垂直animation显示/隐藏视图,但我似乎无法find一个完全正确或不太模糊的。 我有一个布局(撤消栏),在另一个布局下面,并在其他多个小部件之上; 此撤消栏应根据具体情况垂直滑动打开并滑动closures。 目前我所做的只是将视图设置为可见或不可见。 请帮忙。

Android和设置(图片)视图alpha的alpha

是否真的没有对应于setAlpha(int) XML属性? 如果没有,还有什么替代scheme?