利用布局FlowLayout修改设置里字符显示不全的问题

当容器的大小发生变化时,用FlowLayout管理的组件会发生变化,利用这个可以解决RelativeLayout布局中一些字符显示不全的问题

--- /dev/null
+++ b/alps/packages/apps/Settings/res/layout/preference_header_switch_item_linefeed.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2006 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- Layout of a header item in PreferenceActivity. -->
+<com.android.settings.FlowLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content" 
+    android:minHeight="48dp">
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:background="?android:attr/activatedBackgroundIndicator"
+        android:gravity="center_vertical"
+        android:minHeight="48dp"
+        android:paddingRight="?android:attr/scrollbarSize" >
+
+        <ImageView
+            android:id="@+id/icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_marginLeft="6dip"
+            android:layout_marginRight="6dip" />
+
+        <RelativeLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="6dip"
+            android:layout_marginLeft="2dip"
+            android:layout_marginRight="6dip"
+            android:layout_marginTop="6dip"
+            android:layout_weight="1" >
+
+            <TextView
+                android:id="@+android:id/title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:ellipsize="marquee"
+                android:fadingEdge="horizontal"
+                android:singleLine="true"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+
+            <TextView
+                android:id="@+android:id/summary"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignLeft="@android:id/title"
+                android:layout_below="@android:id/title"
+                android:ellipsize="end"
+                android:maxLines="2"
+                android:textAppearance="?android:attr/textAppearanceSmall" />
+        </RelativeLayout>
+    </LinearLayout>
+
+    <Switch
+        android:id="@+id/switchWidget"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:clickable="true"
+        android:focusable="false"
+        android:padding="8dip" />
+
+</com.android.settings.FlowLayout>

--- /dev/null
+++ b/alps/packages/apps/Settings/src/com/android/settings/FlowLayout.java
@@ -0,0 +1,84 @@
+package com.android.settings;
+
+import java.util.Hashtable;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+import android.widget.RelativeLayout;
+
+public class FlowLayout extends RelativeLayout {
+	int mLeft,mRight,mTop,mBottom, curBottom;
+	Hashtable<View, Position> map = new Hashtable<View, FlowLayout.Position>();
+	
+	public FlowLayout(Context context){
+		super(context);
+	}
+	
+	public FlowLayout(Context context, AttributeSet attrs) {
+		super(context, attrs);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Override
+	protected void onLayout(boolean changed, int l, int t, int r, int b) {
+		// TODO Auto-generated method stub
+//		super.onLayout(changed, l, t, r, b);
+		int count = getChildCount();
+        for (int i = 0; i < count; i++) {
+                View child = getChildAt(i);
+                Position pos = map.get(child);
+                if (pos != null) {
+                        child.layout(pos.left, pos.top, pos.right, pos.bottom);
+                } else {
+                        Log.i("MyLayout", "error");
+                }
+        }
+	}
+	
+	public int getPosition(int IndexInRow, int childIndex) {
+        if (IndexInRow > 0) {
+                return getPosition(IndexInRow - 1, childIndex - 1)
+                                + getChildAt(childIndex - 1).getMeasuredWidth()+10;
+        }
+        return 0;
+	}
+	
+	@Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+            // TODO Auto-generated method stub
+            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+            int width = MeasureSpec.getSize(widthMeasureSpec);
+            mLeft = 0;
+            mRight = 0;
+            mTop = 0;
+            mBottom = 0;
+            int j = 0;
+            int count = getChildCount();
+            for (int i = 0; i < count; i++) {
+                    Position position = new Position();
+                    View view = getChildAt(i);
+                    mLeft = getPosition(i - j, i);
+                    mRight = mLeft + view.getMeasuredWidth();
+                    if (mRight >= width) {
+                            j = i;
+//                            mLeft = getPosition(i - j, i);
+                            mLeft = width - view.getMeasuredWidth();
+                            mRight = mLeft + view.getMeasuredWidth();
+                            mTop += getChildAt(i).getMeasuredHeight();
+                    }
+                    mBottom = mTop + view.getMeasuredHeight();
+                    position.left = mLeft;
+                    position.top = mTop;
+                    position.right = mRight;
+                    position.bottom = mBottom;
+                    map.put(view, position);
+            }
+            setMeasuredDimension(width, mBottom);
+    }
+
+	private class Position {
+        int left, top, right, bottom;
+}
+}

--- a/alps/packages/apps/Settings/src/com/android/settings/Settings.java
+++ b/alps/packages/apps/Settings/src/com/android/settings/Settings.java
@@ -522,7 +522,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
                         break;
 
                     case HEADER_TYPE_SWITCH:
-                        view = mInflater.inflate(R.layout.preference_header_switch_item, parent,
+                        view = mInflater.inflate(R.layout.preference_header_switch_item_linefeed, parent,
                                 false);
                         holder.icon = (ImageView) view.findViewById(R.id.icon);
                         holder.title = (TextView)


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FlowLayoutPanel 一些应用程序需要一个布局可随窗体大小的调整或其中内容大小的改变而自动进行适当排列的窗体。在需要动态布局并且不希望在代码中显式处理 Layout 事件时,可考虑使用布局面板。 FlowLayoutPanel是.NET Framework的新增控件。顾名思义,面板可以采用Web窗体的方式给Windows窗体布局FlowLayoutPanel是一个容器,允许以垂直或水平的方式放置包含的控件。除了放置控件之外,还可以剪辑控件。放置的方向使用FlowDirection属性和FlowDirection枚举来设置。WrapContents属性确定在重新设置窗体的大小时,控件是放在下一行、下一列,还是剪辑控件。 FlowLayoutPanel 按特定的流方向排列其内容:水平或垂直。其内容可从一行换到下一行,或者从一列换到下一列。另一种情况是不换行,而是将其内容截掉。 相信大家在做WinForm项目的时候,要对大量的控件进行排序(位置摆放),这个容器肯定最受欢迎,但很遗憾的是,此容器本身虽支持Dock和Anchor属性,但不支持放入此容器内的控件的Dock和Anchor属性(自动调整宽度),也就说,但窗体伸缩,FlowLayoutPanel容器自身可以缩放,但是面的控件就没那么幸运了,不支持自动缩放,这样就必须写方法来触发新的事件来调整控件的大小,这样就会导致窗体的闪烁(重绘)。 借助ManagedSpy工具,我们可以看到此容器面的器件的结构,我们可以在Form1面添加一个事件SizeChanged 对容器面每个器件重新给它大小 就行了。 附件:FlowLayoutPanel的Demo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值