【问题标题】:Textview being overlapped by ImageviewTextview 被 Imageview 重叠
【发布时间】:2016-11-15 18:43:54
【问题描述】:

所以我有一个放在图像视图上方的文本视图。当我将文本添加到 textview 时,它会被 imageview 覆盖。我想要发生的是,当我向 textview 添加更多文本时,imageview 会从文本末尾下方开始向下推。我将如何实现这一目标?

这是我的 activity_route_details.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_route_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.zach.listview.RouteDetails">

<TextView
    android:text="TextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/routeDetailsView"
    android:textSize="18sp"
    android:textAlignment="center" />

<com.example.zach.listview.TouchImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/routeImage"
    android:scaleType="fitCenter"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:adjustViewBounds="false" />


</RelativeLayout>

这是我的 routeDetails.java

package com.example.zach.listview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;



public class RouteDetails extends AppCompatActivity {

TouchImageView routeImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_route_details);

    //back button for route details view
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //TextView for route details
    final TextView routeDetailsView = (TextView) findViewById(R.id.routeDetailsView);
    routeDetailsView.setText(getIntent().getExtras().getString("route"));

    //ImageView for route details
    routeImage = (TouchImageView) findViewById(R.id.routeImage);
    routeImage.setImageResource(getIntent().getIntExtra("imageResourceId", 0));

}

//back button for route details view
@Override
public boolean onSupportNavigateUp(){
    finish();
    return true;
}

}

【问题讨论】:

    标签: java android xml textview imageview


    【解决方案1】:

    添加

    android:layout_below="@+id/routeDetailsView"

    &lt;com.example.zach.listview.TouchImageViewxml 中的定义。

    类似这样的:

    <com.example.zach.listview.TouchImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/routeImage"
        android:scaleType="fitCenter"
        android:layout_below="@id/routeDetailsView"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:adjustViewBounds="false"/>
    

    【讨论】:

    • 感谢完美。但是现在我遇到了一个问题,不是图像视图被推下并且页面变得可滚动,图像只是在同一个屏幕上缩小
    • 尝试将android:adjustViewBounds="false"更改为android:adjustViewBounds="true"
    • 或者使用android:scaleType="centerInside"标签。
    【解决方案2】:

    只需将您的代码放入ScrollView

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ScrollView>
    

    【讨论】:

    • 感谢工作。但是现在我的图像缩放和滚动真的很傻。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2011-12-06
    相关资源
    最近更新 更多