【问题标题】:TextView being pushed off the screen by ImageViewTextView 被 ImageView 推离屏幕
【发布时间】:2013-09-07 12:53:24
【问题描述】:

我遇到了 ImageView 和 TextView 的问题。我有一个问题,当我将 ImageView 的布局宽度和高度设置为“fill_parent”时,我想在它下面显示的 TextView 被推离屏幕。

我必须让 ImageView 来填充屏幕的其余部分,这就是我使用“fill_parent”作为高度和宽度的原因。我已经尝试将“fill_parent”仅用于宽度,“wrap_content”用于高度,但随后整个图像的大小会被调整(更小),就好像我对两者都使用“wrap_content”一样。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_x_high"
android:orientation="vertical" >

<Gallery
    android:id="@+id/Gallery01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</Gallery>

<ImageView
    android:id="@+id/ImageView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:paddingBottom="8dp"
    android:paddingTop="20dp"
    android:layout_below="@+id/Gallery01" >
</ImageView>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/Textgoeshere"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="15sp"
    android:textColor="#CCCCCC"
    android:typeface="serif"
    android:textAlignment="gravity"
    android:layout_below="@+id/ImageView01" />

</RelativeLayout>

【问题讨论】:

  • 嗯,线性布局和权重怎么样?

标签: android textview imageview


【解决方案1】:

您可以将TextView 对齐到父布局的底部,然后将ImageView 低于 Gallery高于 @987654324 @。这样它将填充布局中的其余空间:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_x_high"
android:orientation="vertical" >

<Gallery
    android:id="@+id/Gallery01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</Gallery>

<TextView
    android:id="@+id/textView1"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="goes here"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="15sp"
    android:textColor="#CCCCCC"
    android:typeface="serif"
    android:textAlignment="gravity" />

<ImageView
    android:id="@+id/ImageView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:paddingBottom="8dp"
    android:paddingTop="20dp"
    android:layout_below="@+id/Gallery01"
    android:layout_above="@+id/textView1" >
</ImageView>



</RelativeLayout>

【讨论】:

  • @Jack 将此应用到 ImageView: android:layout_width="wrap_content" android:layout_height="wrap_content" .
  • 这很奇怪,我已经测试过了,它对我有用:),ImageView 固定在 Gallery View 和 TextView 之间。否则,如果您的 ImageView 太大(高度),请尝试使用ScrollView
  • 是的,现在可以了。我发布了我是个白痴并将其应用于不同的项目,无论如何感谢您的帮助,祝您有美好的一天:)
【解决方案2】:

试试这个

<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"
        tools:context=".ActivityHome"
        android:orientation="vertical"
        android:weightSum="1"
         >
    <Gallery
        android:id="@+id/Gallery01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

     >
    </Gallery>



    <ImageView
        android:id="@+id/ImageView01"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:paddingBottom="8dp"
        android:background="@drawable/ic_launcher"
        android:layout_weight="1"
        android:paddingTop="20dp"
        >
    </ImageView>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
            android:gravity="center"
        android:text="Textgoeshere"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="15sp"
        android:textColor="#CCCCCC"
        android:typeface="serif"
        android:textAlignment="gravity"
        android:layout_gravity="bottom"
        />    
        </LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多