【问题标题】:Android Layout Adjustment安卓版面调整
【发布时间】:2013-09-23 05:45:27
【问题描述】:

这是我的移动应用的屏幕截图。我如何调整底部中心的“管理类别”按钮,因为底部的这个黑色空间看起来不太好。

这是我的布局文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listCategory"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="0.9"
        android:background="#FFFFFF"
        android:gravity="top" />

    <Button
        android:id="@+id/btnManageCategory"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:onClick="onButtonClick"
        android:text="Manage Category" 
        android:gravity="center"
        />

</LinearLayout>

【问题讨论】:

  • 您是否尝试将LinearLayout 的高度设置为 wrap_content ?

标签: android layout alignment adjustment


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listCategory"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:gravity="top" />
    <View
         android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1">
    </View>

    <Button
        android:id="@+id/btnManageCategory"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
         android:layout_weight="1"
        android:onClick="onButtonClick"
        android:text="Manage Category" 
        android:gravity="center"


        />

</LinearLayout>

【讨论】:

    【解决方案2】:

    试试这个:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout_root"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    
    <ListView
        android:id="@+id/listCategory"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="0.9"
        android:background="#FFFFFF"
        android:gravity="top" />
    
    <Button
        android:id="@+id/btnManageCategory"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:onClick="onButtonClick"
        android:text="Manage Category" 
        android:gravity="center"
        />
    
    </LinearLayout>
    

    【讨论】:

      【解决方案3】:
      // try this
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/layout_root"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" >
      
          <ListView
              android:id="@+id/listCategory"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"
              android:background="#FFFFFF" />
      
          <Button
              android:id="@+id/btnManageCategory"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:onClick="onButtonClick"
              android:text="Manage Category"
              android:gravity="center"/>
      
      </LinearLayout>
      

      【讨论】:

        【解决方案4】:

        您可以尝试使用weights。您可能不得不使用数字来获得您想要的东西,但给ListView 一个weight 说 0.8 和 0.2 为Button。确保为height 提供0dp 的值。类似的东西

          <ListView
            android:id="@+id/listCategory"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="0.8"
            android:background="#FFFFFF"
            android:gravity="top" />
        
        <Button
            android:id="@+id/btnManageCategory"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:onClick="onButtonClick"
            android:text="Manage Category" 
            android:gravity="center"
            android:layout_weight="0.2"   
            />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-09-25
          • 2012-05-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多