2016-12-23 2 views
-1

Dans mon application, je crée une vue de date en utilisant le code ci-dessous. Je dois créer ces éléments d'interface utilisateur de date plusieurs fois pour faire un calendrier comme l'interface utilisateur tabulaire. J'utilise GridLayoutManager et RecycleView pour créer la vue entière qui ressemblera à un mois. Lorsque l'interface utilisateur est chargée, toutes les textviews de l'interface utilisateur affichent toujours les grandes en grosses polices. Comment je peux réduire le texte proportionnellement? Dois-je ajuster la police par programme ou y a-t-il un moyen d'ajuster le contenu pour l'adapter à l'interface utilisateur disponible?Ajustez texview en fonction de la taille de l'écran pour adapter le contenu à l'échelle appropriée

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.myApps.app1.calendarDayViewFragment"> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/cardview_light_background" 
     tools:context="com.myApps.app1.monthDetailedDayViewFragment" 
     android:id="@+id/layout_detailed_day_view"> 

     <LinearLayout android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true"> 

      <!-- Section Row 2 --> 
      <LinearLayout android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/linear_layout_section_1"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="row_text_1_1" 
        android:textAlignment="textStart" 
        android:id="@+id/textView_day_information_row_1_1" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:textColor="@color/colorPrimary" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="row_text_1_2" 
        android:id="@+id/textView_day_information_row_1_2" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:gravity="right" 
        android:textColor="@color/colorPrimary" /> 
      </LinearLayout> 

      <!-- Section Row 2 --> 
      <LinearLayout android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/linear_layout_section_2" > 

      <LinearLayout android:orientation="vertical" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:id="@+id/linear_layout_section_2_1" 
       android:layout_weight="1" > 

       <!-- Next to Big TEXT, row 1 --> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Section_2_text_row_1" 
        android:textAlignment="textStart" 
        android:id="@+id/textView_day_information1" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:textColor="@color/colorPrimary" /> 

       <!-- Next to Big TEXT, row 2 --> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Section_2_text_row_2" 
        android:textAlignment="textStart" 
        android:id="@+id/textView_day_information2" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:textColor="@color/colorPrimary" /> 

       <!-- Next to Big TEXT, row 3 --> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Section_2_text_row_3" 
        android:textAlignment="textStart" 
        android:id="@+id/textView_day_information3" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:textColor="@color/colorPrimary" /> 

       <!-- Next to Big TEXT, row 4 --> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Section_2_text_row_4" 
        android:textAlignment="textStart" 
        android:id="@+id/textView_day_information4" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:textColor="@color/colorPrimary" /> 

       <!-- Next to Big TEXT, row 5 --> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Section_2_text_row_5" 
        android:textAlignment="textStart" 
        android:id="@+id/textView_day_information5" 
        android:textStyle="normal|bold" 
        android:textSize="16sp" 
        android:textColor="@color/colorPrimary" /> 

      </LinearLayout> 

      <LinearLayout android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:id="@+id/linear_layout_section_2_2" 
       android:layout_weight="1"> 

       <!-- Big Text --> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="१०" 
        android:id="@+id/calendar_day_header" 
        android:textStyle="normal|bold" 
        android:textSize="140dp" 
        android:textColor="@color/colorPrimary" 
        android:gravity="right" /> 

      </LinearLayout> 

     </LinearLayout> 

      <!-- Section Row 3 --> 
      <LinearLayout android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/linear_layout_section_3"> 

      <LinearLayout android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/linear_layout_section_3_1"> 
       <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="text_row_3_1" 
       android:id="@+id/textView_information_row_3_1" 
       android:textStyle="normal|bold" 
       android:textSize="16sp" 
       android:gravity="right" 
       android:textColor="@color/colorPrimary" /> 
       <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="text_row_3_2" 
       android:id="@+id/textView_information_row_3_2" 
       android:textStyle="normal|bold" 
       android:textSize="16sp" 
       android:gravity="right" 
       android:textColor="@color/colorPrimary" /> 
      </LinearLayout> 

     <LinearLayout android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/linear_layout_section_3_2"> 

      <ImageView 
       android:layout_width="32dp" 
       android:layout_height="32dp" android:src="@drawable/ic_image1" 
       android:layout_alignParentRight="true" 
       android:layout_gravity="right"/> 

     </LinearLayout> 

    </LinearLayout> 

     </LinearLayout> 

    </RelativeLayout> 
</FrameLayout> 

Voici le code RecycleView:

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
          android:id="@+id/recyclerview_mothly_dates" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:scrollbars="vertical" 
          android:background="@android:color/holo_green_light" > 

         </android.support.v7.widget.RecyclerView> 

Merci, IamHuM

Répondre

0

créer un dossier multiple pour des valeurs comme celui-ci et coller dimens.xml dans chaque dossier et gérer la taille du texte d'ici même nom avec des valeurs différentes.

values 
values-xhdpi 
values-xxhdpi 
values-xxxhdpi 
values-sw600dp 
values-sw800dp 

<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="१०" android:id="@+id/calendar_day_header" android:textStyle="normal|bold" android:textSize="@dimen/test_140_size" android:textColor="@color/colorPrimary" android:gravity="right" />

NOTE: Donnez une valeur différente de la taille du texte dans sp conformément à la résolution dans chaque fichier dimens.xml avec le même nom.

0

Vous pouvez ajouter cette bibliothèque à votre fichier gradle
compile 'com.intuit.sdp:sdp-android:1.0.3'

Tout ce que vous devez faire est: ajouter android: textSize = "@ dimen/_13sdp"

Vous devez utiliser sdp au lieu de dp, cela met automatiquement à l'échelle votre vue texte ou toute autre vue en fonction des dimensions requises par n'importe quel périphérique quelle que soit sa taille.

espérons que cela résout votre problème.

<TextView 
    android:id="@+id/profile_name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World" 
    android:textSize="@dimen/_13sdp" />