繁体   English   中英

相对布局图像视图翻转滚动视图android

[英]Relative Layout Image View lapping over scroll view android

一

我尝试将image(imageBottom)放在滚动view(scrollView) image(imageBottom)下面,但它与滚动视图的左下角重叠。

我也在imageview尝试过属性layout_below ,但这个技巧layout_below

<?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/myLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    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.rohitkumar.androidtutorial.MainActivity">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageIcon"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="@string/TextString"
        android:textSize="32sp" />

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/textView1"
    android:layout_marginBottom="30dp"
    android:layout_marginTop="10dp">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/longText"
        android:textSize="20sp" />

</ScrollView>

<ImageView
    android:id="@+id/imageIcon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:contentDescription=""
    app:srcCompat="@drawable/course1" />

<ImageView
    android:id="@+id/imageBottom"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:contentDescription="@string/course_image"
    android:src="@drawable/image_1" />

</RelativeLayout>

创建相对布局并将textview和图像图标放在其中:

<RelativeLayout
    android:id="@+id/rl1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
   >

<TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageIcon"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="@string/TextString"
        android:textSize="32sp" />

<ImageView
    android:id="@+id/imageIcon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:contentDescription=""
    app:srcCompat="@drawable/course1" />
</RelativeLayout

在你的滚动视图中添加android:layout_above="@+id/imageBottom"android:layout_below="@+id/rl1"

您只想滚动textview而不需要任何滚动视图,您可以像这样滚动textview:

只需设置

 android:maxLines = "AN_INTEGER"
 android:scrollbars = "vertical"

布局的xml文件中TextView的属性。

然后使用:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

在你的代码中。 并添加android:layout_above="@+id/imageBottom"到你的android:layout_below="@+id/textView1"android:layout_below="@+id/textView1"删除滚动视图布局

<TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/imageBottom"
        android:gravity="center"
        android:text="@string/TextString"
        android:textSize="32sp" />

试试吧。

<?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/myLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
   >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageIcon"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="hi"
        android:textSize="32sp" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/imageBottom"

        android:layout_below="@+id/textView1"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="10dp">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="20sp" />

    </ScrollView>

    <ImageView
        android:id="@+id/imageBottom"
        android:layout_alignParentBottom="true"
        android:layout_width="100dp"
        android:layout_height="100dp"
        />

    <ImageView
        android:id="@+id/imageIcon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:contentDescription=""
         />
</RelativeLayout>

@Rohit Kumar你只需在滚动视图中添加这一行android:layout_above="@+id/imageBottom"android:layout_below="@+id/textView1"

<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/myLinearLayout"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:orientation="vertical"  
    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.rohitkumar.androidtutorial.MainActivity">  

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageIcon"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="Title"
        android:textSize="32sp" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageBottom"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView1"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="10dp">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="this is a simple paragraph that is meant to be nice and easy to type which is why there will be mommas no periods or any capital letters so i guess this means that it cannot really be considered a paragraph but just a series of run on sentences this should help you get faster at typing as im trying not to use too many difficult words in it although i think that i might start making it hard by including some more difficult letters I'm typing pretty quickly so forgive me for any mistakes i think that i will not just tell you a story about the time i went to the zoo and found"
            android:textSize="20sp" />

    </ScrollView>

    <ImageView
        android:id="@+id/imageIcon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:contentDescription="test"
        app:srcCompat="@mipmap/ic_launcher" />

    <ImageView
        android:id="@+id/imageBottom"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@mipmap/ic_launcher" />

</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM