2016-06-15 41 views
0

我有TextView的和按钮每行一个ListView,这是我的布局,内容Android的ListView的视觉误差:按钮重叠TextView的

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Medium Text" 
      android:id="@+id/desc" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="15dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="right"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="70dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_marginRight="15dp" /> 
    </LinearLayout> 

</FrameLayout> 

这是一个screenshoot至极描述错误 http://it.tinypic.com/r/a47ho9/9

回答

1

我会对ListView行不使用FrameLayout,因为难以在FrameLayout中定位项目。只需使用一个LinearLayoutandroid:orientation="horizontal",并把你的TextViewButton在里面。

+0

感谢您的帮助 –

1

使用RelativeLayout可以更容易地正确放置您的小部件我会说。我也建议尝试展平你的布局。这意味着你不应该嵌套这么多的布局。在这种情况下做这件事非常简单。当您将自己的UI设置为优化性能时,您希望拥有尽可能小的嵌套布局。

尝试这样的东西,而不是,可能不完全是你想要的,但也许可以帮助你。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="" 
       android:padding="8dp"> 

    <TextView 
     android:id="@+id/desc" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:text="Medium text" 
     android:layout_centerVertical="true" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:layout_toLeftOf="@+id/button"/> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="70dp" 
     android:text="button" 
     android:layout_centerVertical="true" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"/> 

</RelativeLayout> 

您可以在此处详细了解优化布局https://developer.android.com/training/improving-layouts/optimizing-layout.html