2012-05-16 58 views
0

冲突的我有两个的LinearLayout的Android LinearLayouts彼此

一个包含带有patch9图像作为语音泡和另一个与一个TextView和ImageView的

当我尝试键入到的EditText是开始一个的EditText扩大朝向右手侧,然后开始减小第二的LinearLayout的宽度(细碎的图像)

XML是

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/white" 
android:gravity="center" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="left" 
     android:orientation="vertical" > 

     <EditText 
      android:id="@+id/summaryMessage" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@drawable/greeting_bubble_white" 
      android:gravity="center" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/summaryImage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/picture_frame" /> 

     <TextView 
      android:id="@+id/summaryText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="10dp" /> 
    </LinearLayout> 
</LinearLayout> 

</LinearLayout> 

看起来这

enter image description here

任何想法?

回答

1

其不断扩大的,因为你已经指定了你LinearLayoutlayout_width应该是“wrap_content”,你应该指定一个固定的与DPS维度,所以它不会扩大。 其它用途的weight标签

尝试这个修改:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/white" 
android:gravity="center" 
android:orientation="vertical" > 
<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:gravity="center" 
android:orientation="horizontal" 
android:layout_weight="0.7"> 

    <EditText 
     android:id="@+id/summaryMessage" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/greeting_bubble_white" 
     android:gravity="center" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.3" 
    android:gravity="right" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/summaryImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/picture_frame" /> 

    <TextView 
     android:id="@+id/summaryText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:paddingLeft="10dp" /> 
</LinearLayout> 

不过我建议更多的是你使用这一个:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/white" 
android:gravity="center" 
android:orientation="horizontal" > 

     <EditText 
      android:id="@+id/summaryMessage" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="0.7" 
      android:background="@drawable/greeting_bubble_white" 
      android:gravity="center" /> 

     <TextView 
      android:id="@+id/summaryText" 
      android:layout_weight="0.3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="10dp" /> 
</LinearLayout> 

和你使用复合博士你的summaryText awesomes这里是一个链接,应该可以帮助你:Using Compund Drawables

+0

我改变了根LinearLayout为wrap_content和仍然是相同的结果。我已经尝试了权重标签,如第一篇文章中所示。什么是DPS? – user1177292

+0

我试过了你的建议,但是edittext是在垂直方向上的image/textview之上。我需要同一水平布局的edittext和image/textview,左边的edittext和右边的image/textview – user1177292

+0

请阅读这篇关于dps的文章:http://developer.android.com/guide/practices/screens_support的.html#密度独立性 – Raykud

0

使用相对布局,布局编辑器其实相当好,所以用它来定位你的看法

+0

我觉得LinearLayout容易理解,所以宁愿坚持LinearLayout – user1177292