2013-11-25 36 views
0

我有一个应用程序,我可以找到蓝牙设备。当我开始搜索时,会出现一个对话窗口,在上方显示,配对设备及其下方显示新发现的设备。对话窗口布局上的权重

这个窗口和蓝牙聊天的例子是一样的,我从那里得到它。

会发生什么情况是,如果您有几个配对的设备,新设备的空间会变得非常小。 1

这是该对话窗口中的代码:我用这个代码

<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"/> 

+1

根据设备高度将屏幕分为两部分,并在运行时设置列表视图的高度 – Meenal

+0

或者您可以使用可扩展的'ListView'。 –

+0

@Meenal夏尔马我该怎么做? – masmic

回答

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(); 
     } 
+0

会有一些方法直接在布局上做,而不使用代码? – masmic

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> 
+0

不会做正确的工作。只显示半按钮。新设备从按钮开始加载。是不是最佳性能的最佳方法 – masmic

+0

我认为你需要布局背景上的透明图像。 –