Textview被Imageview重叠

问题描述:

所以我有一个textview,我放在imageview上方。当我将文本添加到textview时,它被imageview覆盖。我想要发生的是,当我向文本视图添加更多文本时,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; 
} 

} 

添加

android:layout_below="@+id/routeDetailsView"

<com.example.zach.listview.TouchImageView定义在xml

事情是这样的:

<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"/> 
+0

感谢的作品完美。但现在我有一个问题,而不是imageview被推下来,页面变得滚动,图像只是缩小在同一屏幕上 – user4297729

+0

尝试更改'android:adjustViewBounds =“false”'到'android:adjustViewBounds =“ true“' –

+0

或者使用'android:scaleType =”centerInside“'标签。 –

只要把你的代码中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> 
+0

谢谢你的工作。但现在我的图像缩放和滚动非常愚蠢。 – user4297729