【问题标题】:Placing image in Left side in ImageView, in case ImageView takes full width of screen?将图像放置在 ImageView 的左侧,以防 ImageView 占据整个屏幕宽度?
【发布时间】:2016-09-08 00:37:22
【问题描述】:
<ImageView
    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/nextarrow_final"
/>

我希望这张图片在左侧。

有什么帮助吗??

【问题讨论】:

  • android:gravity="left"
  • 将 imgaeview 放入 Linearlayout 垂直,在设置 Gravity of linear layout to left 时使用相同的参数,设置 Imageview 参数以包裹内容
  • 试试这个 android:scaleType="fitStart" 参考stackoverflow.com/questions/655994/…
  • @AmolTate : android:gravity="left" 在 ImageView 上不起作用。
  • 使用 layout_gravity="left"

标签: android


【解决方案1】:

@阿尼什·米塔尔

我在这两种布局中描述您的问题解决方案:

1> 线性布局

这段代码放在主线性布局中

      <LinearLayout
        android:id="@+id/learlayout1"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:gravity="center" >

        <ImageView
            android:id="@+id/img"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:src="@drawable/facebook" />

        <View
            android:id="@+id/view1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

2> 相对布局

android:scaleType="fitStart"

此代码也支持多屏....!!!

【讨论】:

  • 哈哈哈。我上面说的。我想保持宽度为fill_parent。并且您将父宽度设为“wrap_content”。
  • 我知道您的问题,但如果您在图片右侧有一些空间,则此任务已满
  • android:scaleType="fitStart" 在 android:layout_width="match_parent" 的情况下对我有用!
【解决方案2】:

在你的布局中试试这个。 (android:scaleType="fitStart")

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorDefaultBg">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scaleType="fitStart"
            android:id="@+id/image_logo"
            android:src="@drawable/my_logo" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text=""
            android:padding="10dp"
            android:id="@+id/text_title"
            android:layout_gravity="center_vertical" />

    </LinearLayout>

【讨论】:

    【解决方案3】:

    尝试:

    android:layout_alignParentLeft="true"
    

    【讨论】:

      【解决方案4】:

      试试这个。

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center"
          android:orientation="vertical">
      
      
           <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="left"
          android:src="@drawable/nextarrow_final"/>
      
      </LinearLayout>
      

      希望这会有所帮助:)

      【讨论】:

      • 因为您的图像宽度为“fill_parent”,您是否希望图像宽度覆盖整个屏幕?如果没有,那么尝试放置一些像素,例如。 android:layout_width="80dp" 而不是使用 "fill_parent"。
      【解决方案5】:

      您提到宽度是“填充父级”。因此,它需要全宽而不是为线性布局内的宽度和高度提供“包装内容”,它左对齐。我认为它对你有帮助。

      【讨论】:

      • 我知道这一点。但我想保持宽度“fill_parent”并在其中,筛选小图像。
      【解决方案6】:

      在你的布局中试试这个:

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" >
      <ImageView
          android:id="@+id/image"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" />
      

      在你的代码中添加这个:

      image.setScaleType(ImageView.ScaleType.FIT_XY );
      

      【讨论】:

      • ScaleType.FIT_XY 将不起作用。而是 ScaleType fitStart 有效。 :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2023-04-04
      相关资源
      最近更新 更多