1

In meiner Anwendung zeige ich ein Bild im Vollbildmodus (was eigentlich eine neue Aktivität ist) unter Verwendung der Bibliothek PhotoView. Das Beispielbild ist unten, also muss der Text genau so angezeigt werden.Wie zeige ich Text auf `PhotoView` an?

enter image description here

ich den XML-Code geschrieben haben, überprüfen Sie bitte unter

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_view_full_screen_image" 
    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.theace.fullscreen.ViewFullScreenImage" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:id="@+id/li1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

       <com.github.chrisbanes.photoview.PhotoView 
        android:id="@+id/photo_view" 
        android:layout_width="match_parent" 
        android:layout_centerInParent="true" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="40dp" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="30dp" 
        android:layout_marginBottom="10dp" 
        android:textColor="@android:color/white" 
        android:id="@+id/tv1"/> 


     </LinearLayout> 


</LinearLayout> 

Unten ist mein zugehörige Java-Code

package com.example.theace.fullscreen; 

import android.graphics.Color; 
import android.net.Uri; 
import android.support.v4.app.NavUtils; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.MenuItem; 
import android.view.Window; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 
import com.github.chrisbanes.photoview.PhotoView; 
import com.squareup.picasso.Picasso; 

public class ViewFullScreenImage extends AppCompatActivity { 

    RelativeLayout li1; 
    TextView textView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_view_full_screen_image); 
     li1 = (RelativeLayout) findViewById(R.id.activity_view_full_screen_image); 
     li1.setBackgroundColor(Color.BLACK); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     textView = (TextView)findViewById(R.id.tv1); 

     loadImage(); 
    } 

    public void loadImage(){ 

     Uri imageUrl = Uri.parse("https://s-media-cache-ak0.pinimg.com/736x/39/c7/64/39c764abd350c509f76c6362780a3a78--outdoor-portraits-outdoor-portrait-photography.jpg"); 

     PhotoView photoView = (PhotoView) findViewById(R.id.photo_view); 
     Picasso.with(this).load(imageUrl).into(photoView); 
     textView.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tristique nunc turpis, at congue est molestie a. Etiam nec cursus arcu. Curabitur vestibulum ligula vitae velit rutrum sollicitudin. Phasellus imperdiet ultrices semper. Morbi laoreet magna sit amet mi vulputate pharetra. Proin faucibus maximus massa, sit amet vestibulum elit posuere eget."); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case android.R.id.home: 
       NavUtils.navigateUpFromSameTask(this); 
       return true; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 
} 

Wie kann ich dieses Problem beheben?

+0

Stimmen Bezug nach unten und in der Nähe Stimmen zu dieser Frage, SO "Weg" ist zu sagen, warum Sie unten abgestimmt oder geschlossen abgestimmt haben, und nicht nur Drücke einen Knopf und renne. Ich sehe keinen Grund für eine Down-Abstimmung oder eine enge Abstimmung. SO brauchen wirklich Untersuchungsteam auf diesen "hit and run" Leuten. –

+0

@PeakGen: Sie wurden falsch informiert. Der SO-Weg besteht darin, dass die Leute aus irgendeinem Grund abstimmen können, und zwar anonym, solange sie sich nicht auf einen Benutzer konzentrieren. Viele Vorschläge, dies bei _Meta Stack Overflow_ zu ändern, sind fehlgeschlagen. – halfer

Antwort

1

einfach den Code unten verwenden

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_view_full_screen_image" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.theace.fullscreen.ViewFullScreenImage" 
    android:orientation="vertical"> 


     <com.github.chrisbanes.photoview.PhotoView 
      android:id="@+id/photo_view" 
      android:layout_width="match_parent" 
      android:layout_centerInParent="true" 
      android:layout_height="match_parent" 
      android:scaleType="center"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_alignParentBottom="true" 
      android:textColor="@android:color/white" 
      android:layout_gravity="bottom|center_horizontal" 
      android:id="@+id/tv1"/> 


</FrameLayout> 
0

versuchen dies Ihr activity_view_full_screen.xml wie diese

Gebrauch machen RelativeLayout und machen Sie Ihre TextView zu android:layout_alignParentBottom="true"

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_view_full_screen_image" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<com.github.chrisbanes.photoview.PhotoView 
    android:id="@+id/photo_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:scaleType="fitXY" 
    android:layout_marginBottom="40dp" 
    android:src="@drawable/disha" /> 



    <TextView 
     android:id="@+id/tv1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:gravity="center" 
     android:padding="5dp" 
     android:layout_alignParentBottom="true" 
     android:background="#9a080808" 
     android:text="@string/abc" 
     android:textColor="@android:color/white" /> 


</RelativeLayout> 
+0

Sorry, aber das ist nicht die Lösung. Sie zeigen den Text unterhalb des Bildes an, wodurch das Bild unabhängig vom Inhalt über dem Text angezeigt wird. Ich habe auch versucht, einen langen Text von 50 Wörtern hinzuzufügen, die Mehrheit des Textes wurde einfach nicht sichtbar. Der Text sollte über dem unteren Teil des Bildes sein (wenn das Bild groß genug ist) –

+0

hast du nicht ..? –

+0

Der Text sollte wie in dem Screenshot sein, den ich zur Verfügung gestellt habe. Bitte überprüfen Sie, dass der Text nicht unter dem Bild, sondern im unteren Teil des Bildes liegt. Der Screenshot stammt aus WhatsApp. Dort wird der Text direkt unter dem Bild in einem schwarzen Hintergrund angezeigt, wenn das Bild nicht "groß genug" ist, um FULLSCREEN angezeigt zu werden, ansonsten wird der Text wie im Screenshot angezeigt. –

Verwandte Themen