Android:占据整个屏幕宽度的子布局

Android:占据整个屏幕宽度的子布局,android,android-layout,Android,Android Layout,我有一个线性布局作为父布局,有三个子布局,我试图通过从webservice获取来显示子布局中的图像 我的一些图像占据了整个屏幕的宽度,这是不应该发生的。如何避免我的孩子布局占据整个屏幕的宽度 这是我的密码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_paren

我有一个线性布局作为父布局,有三个子布局,我试图通过从webservice获取来显示子布局中的图像

我的一些图像占据了整个屏幕的宽度,这是不应该发生的。如何避免我的孩子布局占据整个屏幕的宽度

这是我的密码

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:baselineAligned="false"
  android:layout_weight="9">

<LinearLayout
    android:id="@+id/one"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:gravity="left"
    android:layout_alignParentLeft="true"
    android:orientation="vertical"/>

<LinearLayout
    android:id="@+id/two"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:gravity="center"
    android:layout_toRightOf="@id/one"
    android:orientation="vertical"/>


   <LinearLayout
    android:id="@+id/three"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:gravity="right"
    android:layout_alignParentRight="true"
    android:orientation="vertical"/>

  </LinearLayout>


您已将权重应用于线性布局,要使权重适用,请将布局宽度更改为0dp

有多种方法

  • 在布局中添加图像视图,并以dp为其指定宽度+高度
  • 像这样

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        android:layout_weight="9">
    
        <LinearLayout
            android:id="@+id/one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:gravity="left"
            android:layout_alignParentLeft="true"
            android:orientation="vertical">
    
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:id="@+id/imageView"
                android:layout_gravity="center" />
        </LinearLayout>
    
        <LinearLayout
         .....
    
        <LinearLayout
         .....
    
    </LinearLayout>
    

    查找更多详细信息

    谢谢,您的意思是应该将上述代码添加到父布局??您必须对包含imageview的线性布局执行此操作,并为其设置适当的权重。谢谢,我已更改了包含imageview的所有子布局的布局宽度,但它不起作用,所有三个子视图的权重值应该是多少?发布布局的全部代码有imageview我有一个带有imageview的布局,它通过代码在我的每个子布局中膨胀,我现在无法显示。但问题是有些图像是按照我的要求来的,有些图像的imageview宽度是占据了整个布局。不知道在这里做什么。
    CENTER
    Center the image in the view, but perform no scaling. 
    
    CENTER_CROP 
    Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). 
    
    CENTER_INSIDE
    Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). 
    
    FIT_CENTER
    Scale the image using CENTER.
    
    
    FIT_END
    Scale the image using END. 
    
    FIT_START
    Scale the image using START. 
    
    FIT_XY
    Scale the image using FILL. 
    
    MATRIX 
    Scale using the image matrix when drawing.