XML android布局隐藏图标

爪子

我正在编写一个Android应用程序,但遇到了奇怪的事情。即,这是我图标的可见性。它应该在屏幕的右侧。

当我将其放在左侧时,就可以了,它是这样可见的:

在此处输入图片说明

但是当我说对了,它看起来像这样:

在此处输入图片说明

我的代码如下所示:

   <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/_scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="@dimen/space_medium" >

         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginBottom="15dp" >

            <TextView
                android:id="@+id/_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginLeft="10dp"
                android:text="@string/title"
                android:textColor="#666666" 
                android:textSize="20sp"/>

            <ImageView
                android:id="@+id/image"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:gravity="top"
                android:alpha=".50"
                android:src="@drawable/paprika" />

        </LinearLayout>

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:text="@string/description"
            android:textColor="#666666" />

        <Button
            android:id="@+id/_view"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/button"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="@dimen/space_small"
            android:background="@drawable/rect_rounded_light_blue"
            android:text="Button"
            android:textColor="#fff" /> 

    </LinearLayout>    
</ScrollView>
Phantômaxx

一些注意事项:

  • 您不需要2个嵌套的LinearLayouts,一个RelativeLayout即可处理所有View(更少的布局=更好的性能)。
  • 您是否尝试过将图像不放置在ImageView中,而是直接放置在TextView中(较少的Views =更好的性能)?称为复合可绘制对象

    android:drawableTop | Left | Right | Bottom =“ @ drawable / your_image”

这也将防止Z索引重叠。

因此,这就是我将其组合在一起的方式:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/_scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:fillViewport="true"
    >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="@dimen/space_medium"
        >
        <TextView
            android:id="@+id/_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="10dp"
            android:drawableRight="@drawable/paprika"
            android:drawablePadding="8dp"
            android:text="@string/title"
            android:textColor="#667"
            android:textSize="20sp"
        />
        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/_title"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="15dp"
            android:text="@string/description"
            android:textColor="#667"
        />
        <Button
            android:id="@+id/_view"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/button"
            android:layout_below="@id/description"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="@dimen/space_small"
            android:background="@drawable/rect_rounded_light_blue"
            android:text="Button"
            android:textColor="#fff"
        />
    </RelativeLayout>
</ScrollView>

要以编程方式设置复合可绘制对象(一旦您拥有对TextView的引用),只需使用该setCompoundDrawablesWithIntrinsicBounds()方法来分配一个或多个复合图像,如此处所述:http : //developer.android.com/reference/android/widget/TextView .html#setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

XML中的Android图标

来自分类Dev

XML Android布局问题

来自分类Dev

XML Android布局问题

来自分类Dev

XML Android定位布局

来自分类Dev

Android-XML布局

来自分类Dev

Android XML 布局设计

来自分类Dev

android studio中新xml布局的右下角的此邮件图标是什么?

来自分类Dev

Android:如何在xml布局中隐藏/显示浮动操作按钮(fab)

来自分类Dev

XML布局中的Android GLSurfaceView

来自分类Dev

Android底表布局XML

来自分类Dev

xml android准则约束布局

来自分类Dev

xml中的Android框架布局

来自分类Dev

XML布局中的Android GLSurfaceView

来自分类Dev

android app:布局xml文件

来自分类Dev

android:xml布局中的OnDraw

来自分类Dev

Android布局XML旋转方向

来自分类Dev

抽屉布局菜单额外图标从 xml 添加标题右侧

来自分类Dev

Android Studio:InvalidVirtualFileAccessException尝试呈现XML布局

来自分类Dev

带有图像按钮的Android XML布局

来自分类Dev

Android XML布局中条件语句的语法

来自分类Dev

从Android中的xml布局获取节点

来自分类Dev

将Xml布局到我的android应用

来自分类Dev

Android:Row.xml的相对布局

来自分类Dev

Eclipse抱怨android布局xml文件

来自分类Dev

使用xml的android布局中的全角按钮

来自分类Dev

Android XML与代码表布局差异

来自分类Dev

Android图像叠加层中的XML布局

来自分类Dev

Android XML布局声明(纵向,横向模式)

来自分类Dev

带有图像按钮的Android XML布局