-3

Xamarin에는 각 조각에 에 간단한 Bitmap을 표시하는 일부 조각이있는 ViewPager이 있습니다.ImageView 아래에 텍스트 표시

각 조각마다 이러한 이미지 아래에 텍스트를 추가해야합니다.

rootView = inflater.Inflate(Resource.Layout.ViewPagerItemWithImage, container, false); 
imageView = rootView.FindViewById<ImageView>(Resource.Id.image); 
DownloadAsyncBitmap (imageURI, imageView); 
imageView.SetScaleType (ImageView.ScaleType.Center); 

내가 위의 코드와 유사한 코드를 작성하는 데 도움이 있습니다 : 여기

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

는 관련 OnCreateView 코드 :

는 다음 각 조각에 대한 내 현재 ViewPagerItemWithImage 레이아웃 코드 대신 일부 텍스트는 ImageView 아래에 표시됩니까?

ViewPagerItemWithImageAndText 레이아웃 코드를 : 여기에

는 내가 지금까지 무엇을 가지고

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <TextView 
     android:id="@+id/myImageViewText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/image" 
     android:layout_alignTop="@+id/image" 
     android:layout_alignRight="@+id/image" 
     android:layout_alignBottom="@+id/image" 
     android:layout_margin="1dp" 
     android:gravity="center" 
     android:layout_gravity="center_horizontal" 
     android:text="This is an image" 
     android:textColor="#000000" /> 
</LinearLayout> 

OnCreateView 코드 :

rootView = inflater.Inflate(Resource.Layout.ViewPagerItemWithImageAndText, container, false); 
imageView = rootView.FindViewById<ImageView>(Resource.Id.image); 
textView = rootView.FindViewById<TextView>(Resource.Id.myImageViewText); 
DownloadAsyncBitmap (imageURI, imageView); 

텍스트가 전혀 표시되지 않습니다.

도와 드릴까요? 사전

답변

0

코드 아래에보십시오 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:weightSum="8" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="7" 
    /> 

<TextView 
    android:id="@+id/myImageViewText" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="1dp" 
    android:gravity="center" 
    android:text="This is an image" 
    android:textColor="#000000" /> 
</LinearLayout> 
+0

고마워, 그 것이 잘 작동합니다. – user3736648

1

에서

덕분에이 코드를보십시오 : 부동산 아래 ViewPagerItemWithImageAndText layout code:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:id="@+id/myImageViewText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/image" 
     android:layout_alignTop="@+id/image" 
     android:layout_alignRight="@+id/image" 
     android:layout_alignBottom="@+id/image" 
     android:layout_margin="1dp" 
     android:gravity="center" 
     android:layout_gravity="center_horizontal" 
     android:text="This is an image" 
     android:textColor="#000000" /> 
</LinearLayout> 

에 대한 귀하의 항목이 수직 따라서 당신의 텍스트 뷰는 이미지의 아래가 될 것이다 드릴 것입니다.

android:orientation="vertical" 
+0

난 여전히 텍스트를 볼 수 없습니다. ImageView와 관련이 있나요? layout_height = "match_parent"? – user3736648

+0

내 대답을 업데이트했습니다. 다시 시도하십시오. –

1

당신은 당신의 이미지 뷰의 지속에 match_parent의 폭과 높이를 지정하는 공간을받지 않습니다있는 텍스트 뷰는 일부 값으로 이미지 뷰의 레이아웃 변경 높이에 표시 할 수 있습니다 또는 대안 FrameLayout이 사용하지만에 오버레이 텍스트를 표시합니다 이미지 뷰. 사용이 코드

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="9" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:layout_weight="1" 
     android:src="@drawable/abc_ab_bottom_solid_dark_holo" /> 

</LinearLayout> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</LinearLayout> 
+0

죄송합니다.이 XML 코드를 올바르게 포맷 할 수 없으며 잘못된 XML 오류가 발생합니다 ... – user3736648

관련 문제