我在Android上遇到了LinearLayout的问题.我有四个按钮.每个按钮都有固定的大小,但文本的长度可能不同.
我的问题是它们不与每个顶部对齐.它们看起来与每个按钮内部文本的顶部对齐,这取决于按钮内部的行数(参见图片).
此外,我想继续使用LinearLayout,因为我最终将使用代码将基于数据库中的数据添加按钮.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent">
<Button android:text="Line1 Line2" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
<Button android:text="Line1 Line2 Line3" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
<Button android:text="Line1" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
<Button android:text="Line1" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

好的,我自己就找到了答案.您必须将android:baselineAligned ="false"添加到LinearLayout或任何其他可能显示相同行为的类似控件.
您还可以使用名为"Toggle Baseline Alignment"的按钮在UI设计器中修复此问题.
所以生成的代码是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:baselineAligned="false" android:layout_width="match_parent" android:layout_height="match_parent">
<Button android:text="Line1 Line2" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
<Button android:text="Line1 Line2 Line3" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
<Button android:text="Line1" android:textSize="30dp" android:layout_width="160dp" android:layout_height="120dp"></Button>
<Button android:text="Line1" android:textSize="30dp" android:layout_width="160dp" …Run Code Online (Sandbox Code Playgroud) 我有一个使用大量socketio请求的应用程序,我发出批量请求.在接收数据时,我必须遍历列表以添加和删除项目:
List carlist;
void receiveData(Map data) {
// Need a lock here
for (var i = 0; i < carlist.lenght;) {
if (data[carlist[i]['name']]['color'] == carlist[i]['color']) {
carlist.removeAt(i);
onDeleteCar(data); // Update the UI.
}
}
// Need a release lock here
}
Run Code Online (Sandbox Code Playgroud)
因为我需要修改列表,所以我不能在没有互斥的情况下工作.
有人有想法吗?
我正在使用相机,我正在使用文档中给出的完全相同的示例:http: //developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview html的
我在Android 3.1和3.2的Xoom上运行示例.
我的问题是当我锁定并解锁Xoom时,相机不会回来.在我锁定平板电脑之前,图像与最后一个图像保持一致,红灯也没有回来.
如果有人能帮助我,我会很感激.