Textview与Imageview重叠

时间:2016-11-15 18:43:54

标签: java android xml textview imageview

所以我有一个textview,我放在imageview上面。当我向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;
}

}

2 个答案:

答案 0 :(得分:0)

添加

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

答案 1 :(得分:0)

只需将您的代码放入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>