我有一个应用程序,我找到蓝牙设备。当我开始搜索时,会出现一个对话窗口,它显示在上方,配对设备及其下方,显示新找到的设备。
此窗口与蓝牙聊天示例相同,我从那里得到它。
如果您有多个配对设备,新设备的空间会变得非常小。
这是此对话窗口的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/title_paired_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_paired_devices"
android:textIsSelectable="true"
android:visibility="gone"
android:background="#666"
android:textColor="#fff"
android:paddingLeft="5dp" />
<ListView android:id="@+id/paired_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:layout_weight="1"/>
<TextView android:id="@+id/title_new_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_other_devices"
android:textIsSelectable="true"
android:visibility="gone"
android:background="#666"
android:textColor="#fff"
android:paddingLeft="5dp"/>
<ListView android:id="@+id/new_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:layout_weight="2"/>
<Button android:id="@+id/button_scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_scan"/>
答案 0 :(得分:0)
我使用了这段代码,并以20-80
的比例划分屏幕try {
private int imageHeight1, imageHeight2;
Display mDisplay = getActivity().getWindowManager()
.getDefaultDisplay();
if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) < 13) {
int height = mDisplay.getHeight();
imageHeight1 = (int) (height * 0.2);
imageHeight2 = height - imageHeight1;
} else {
Point size = new Point();
mDisplay.getSize(size);
imageHeight1 = (int) (size.y * 0.2);
imageHeight2 = size.y - imageHeight1;
}
try {
listview1.getLayoutParams().height = imageHeight1;
listview2.getLayoutParams().height = imageHeight2;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 1 :(得分:0)
试试这段代码......
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".9"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:orientation="vertical" >
<TextView
android:id="@+id/title_paired_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666"
android:paddingLeft="5dp"
android:text="title_paired_devices"
android:textColor="#fff"
android:textIsSelectable="true"
/>
<ListView
android:id="@+id/paired_devices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stackFromBottom="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:orientation="vertical" >
<TextView
android:id="@+id/title_new_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666"
android:paddingLeft="5dp"
android:text="title_other_devices"
android:textColor="#fff"
android:textIsSelectable="true" />
<ListView
android:id="@+id/new_devices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stackFromBottom="true" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="vertical" >
<Button
android:id="@+id/button_scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button_scan" /> </LinearLayout>
</LinearLayout>