2016-09-26 49 views
1

one相對佈局圖像查看精研過滾動視圖的Android

我試圖把image(imageBottom)下方滾動view(scrollView)但重疊左滾動視圖的右下角。

我也曾嘗試屬性layout_belowimageview但這一招力的工作。

<?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> 

回答

0

在其中創建一個相對佈局和放置的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"在你的滾動視圖

0

要滾動只比你不需要任何的TextView滾動視圖,可以讓TextView的滾動這樣的:

只需設置

在佈局的xml文件你的TextView的和
android:maxLines = "AN_INTEGER" 
android:scrollbars = "vertical" 

性能。

然後使用:

yourTextView.setMovementMethod(new ScrollingMovementMethod()); 

在你的代碼。 並添加android:layout_above="@+id/imageBottom"到你的TextView和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" /> 
0

嘗試了這一點。

<?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> 
+0

感謝alot..this解決方案工程.. –

+0

歡迎,並請你接受:d – Pavan

0

@Rohit庫馬爾你剛剛加入這一行中滾動視圖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> 
+0

感謝alot..this解決方案.. –

+0

@ Rohit庫馬爾然後請接受我的答案..並歡迎。 –

+0

不錯答案Dileep –

相關問題