2015-11-07 3 views
2

Hii guys Я попробовал LinearLayout, внутри которого я разместил несколько текстовых файлов. Я полностью использую веса для каждого вида. Проблема возникает, когда данные становятся слишком длинными, а textview не показывает их полностью. Я также пробовал tabletlayout, но эта вещь также не работает beacuse, в конечном итоге tablelayout находится внутри линейного макета, имеющего вес, поэтому он не выходит за пределы определенного предела. Я хочу знать, как можно прокручивать активность, показывая все данные при использовании весов.Как сделать всю активность прокручиваемой в соответствии с данными внутри нее

+0

показать свой XML-файл – Destro

ответ

5

Использование Scrollview в xml Макет вашей деятельности.

Пример: XML-код для вашей деятельности:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:fillViewport="false"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="200dp" 
      android:scaleType="centerCrop" 
      android:src="@drawable/image" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="KNOW MORE" /> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/title" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/description" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 
    </LinearLayout> 
</ScrollView> 
+0

я говорил об использовании весов полностью и не использовать дп и т.д., когда я использую гири моего TextView имеет ограниченную область show.How я могу сделать такую ​​прокрутку, используя weights.I хотят показать полностраничные прокрученные данные –

2

Вы можете использовать Scroll View с Linear Layout, а также с относительным макетом.

Вы можете попробовать этот код, просто скопировать и вставить файл XML. U'll получить ваш анс :)

  <?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true"> 

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:background="@android:color/black" 
> 

<TextView 
    android:id="@+id/TV_Welcome" 
    android:text="ADD YOUR VEHICLE" 
    android:layout_marginLeft="70dp" 
    android:layout_marginTop="10dp" 
    android:textSize="20dp" 
    android:layout_centerHorizontal="true" 

    android:textColor="@color/menu_color" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical|center_horizontal"/> 


<RelativeLayout 
    android:id="@+id/RelativeLayout01" 
    android:layout_below="@+id/TV_Welcome" 
    android:layout_margin="10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 


    <TextView 
     android:id="@+id/TV_BlockNo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Block No:" 
     android:textColor="@color/version_color" 
     android:layout_marginLeft="10dp" 
     android:textSize="15dp" 
     android:layout_alignParentLeft="true" 
     android:gravity="left" 

     /> 

    <Spinner 
     android:id="@+id/Spinner_BlockNo" 
     android:layout_marginLeft="30dp" 
     android:layout_toRightOf="@+id/TV_BlockNo" 
     android:background="#558cff" 
     android:layout_width="300dp" 
     android:layout_height="wrap_content"> 

    </Spinner> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/RelativeLayout02" 
    android:layout_margin="10dp" 
    android:layout_below="@+id/RelativeLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/TV_FlatNo" 
     android:text="Flat NO:" 
     android:textSize="15dp" 
     android:layout_marginLeft="10dp" 
     android:textColor="@color/version_color" 

     /> 

    <Spinner 
     android:id="@+id/Spinner_FlatNo" 
     android:layout_marginLeft="42dp" 
     android:layout_toRightOf="@+id/TV_FlatNo" 
     android:background="#558cff" 
     android:layout_width="300dp" 

     android:layout_height="wrap_content"></Spinner> 

</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/RelativeLayout03" 
    android:layout_below="@+id/RelativeLayout02" 
    android:layout_margin="10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 


    <TextView 
     android:id="@+id/TV_VehicleNo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Vehicle No:" 
     android:textColor="@color/version_color" 
     android:layout_marginLeft="10dp" 
     android:textSize="15dp" 
     android:layout_alignParentLeft="true" 
     android:gravity="left" 

     /> 

    <EditText 
     android:id="@+id/ET_VehicleNo" 
     android:layout_marginLeft="20dp" 
     android:hint="Enter Vehicle No" 
     android:textColorHint="@color/menu_glow" 
     android:textSize="20dp" 
     android:layout_toRightOf="@+id/TV_VehicleNo" 
     android:textColor="#558cff" 
     android:layout_width="400dp" 
     android:layout_height="wrap_content" 

     /> 


</RelativeLayout> 


<RelativeLayout 
    android:id="@+id/RelativeLayout04" 
    android:layout_margin="10dp" 
    android:layout_below="@+id/RelativeLayout03" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/TV_VehicleType" 
     android:text="Vehicle Type:" 
     android:textSize="15dp" 
     android:layout_marginLeft="10dp" 
     android:textColor="@color/version_color" 

     /> 

    <Spinner 
     android:id="@+id/Spinner_VehicleType" 
     android:layout_marginLeft="10dp" 
     android:layout_toRightOf="@+id/TV_VehicleType" 
     android:background="#558cff" 
     android:layout_width="300dp" 
     android:layout_height="wrap_content"> 

    </Spinner> 

</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/RelativeLayout05" 
    android:layout_margin="10dp" 
    android:layout_below="@id/RelativeLayout04" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/TV_OwnerName" 
     android:text="Owner Name:" 
     android:textSize="15dp" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:gravity="left"> 
    </TextView> 
    <EditText 
     android:id="@+id/ET_OwnerName" 
     android:hint="Enter Owner Name" 
     android:textColorHint="@color/menu_glow" 
     android:inputType="textPersonName" 
     android:layout_marginLeft="20dp" 
     android:textSize="20dp" 
     android:layout_toRightOf="@id/TV_OwnerName" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="400dp"> 
    </EditText> 
</RelativeLayout> 


<RelativeLayout 
    android:id="@+id/RelativeLayout06" 
    android:layout_margin="10dp" 
    android:layout_below="@id/RelativeLayout05" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/TV_MobileNo" 
     android:text="Mobile No:" 
     android:textSize="15dp" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:gravity="left"> 
    </TextView> 
    <EditText 
     android:id="@+id/ET_MobileNo" 
     android:layout_marginLeft="40dp" 
     android:hint="Enter 10 digit" 
     android:textColorHint="@color/menu_glow" 
     android:inputType="phone" 
     android:textSize="20dp" 
     android:layout_toRightOf="@id/TV_MobileNo" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="200dp" 

     > 
    </EditText> 
</RelativeLayout> 


<RelativeLayout 
    android:id="@+id/RelativeLayout07" 
    android:layout_margin="10dp" 
    android:layout_below="@id/RelativeLayout06" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/TV_TelNo" 
     android:text="Telephone No:" 
     android:textSize="15dp" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 
    </TextView> 
    <EditText 
     android:id="@+id/ET_TelNo" 
     android:layout_marginLeft="20dp" 
     android:hint="Enter Telephone No" 
     android:textColorHint="@color/menu_glow" 
     android:inputType="number" 
     android:textSize="17dp" 
     android:layout_toRightOf="@id/TV_TelNo" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 
    </EditText> 
</RelativeLayout> 


<RelativeLayout 
    android:id="@+id/RelativeLayout08" 
    android:layout_margin="0dp" 
    android:layout_below="@id/RelativeLayout07" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/TV_Example" 
     android:text="(Example:0141-2206923)" 
     android:layout_marginLeft="120dp" 
     android:textSize="10dp" 
     android:textColor="@color/version_color" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 
    </TextView> 
</RelativeLayout> 

<ImageView 
    android:id="@+id/ImageView_Submit" 
    android:layout_marginTop="5dp" 
    android:layout_marginLeft="100dp" 
    android:layout_centerInParent="true" 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:src="@drawable/submit" 
    android:layout_below="@id/RelativeLayout08" 
    android:onClick="doSubmit"></ImageView> 

    </RelativeLayout> 
</ScrollView> 
+0

Я говорил об использовании весов полностью и не использовал dp и т. д., когда я использую весы, у моего текстового вида есть ограниченная область для показа. Как я могу делать такую ​​прокрутку при использовании весов. Я хочу показать полноразмерные прокрученные данные –

+0

Что высота и ширина, которые вы задали в своем макете. Потому что с layout_weight вы можете указать соотношение размеров между несколькими видами. Например. у вас есть MapView и таблица, которая должна отображать некоторую дополнительную информацию на карте. Карта должна использовать 3/4 экрана, а таблица должна использовать 1/4 экрана. Затем вы установите для layout_weight карты значение 3 и layout_weight таблицы равным 1. Чтобы получить его работу, вы также должны установить высоту или ширину (в зависимости от вашей ориентации) до 0px. –

+0

Надеюсь, это поможет вам, если не thn gv me ваш единственный xml-код, я исправлю этот .... :) :) –

0

В основном вы должны поместить весь макет XML в целях прокрутки. См. Другие примеры кода.

+0

Я говорил об использовании весов полностью и не использовал dp и т. Д., Когда я использую весы, которые у меня есть ограниченную область для показа. Как я могу выполнять такую ​​прокрутку при использовании весов. Я хочу показать полные страницы с прокруткой данных. –

0

Вы можете сделать свою деятельность прокручиваемой с помощью ScrollView. Его очень простой и эффективный способ использования. Просто скопируйте код ScrollView снизу и вставьте его в свой XML-файл макета. Вы также можете использовать этот ScrollView с линейным и относительным макетом. Просто нужно помнить одну вещь, ScrollView может иметь только один дочерний виджет. Если вы хотите больше детей, тогда их можно перевернуть в один контейнер.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/xyz.png"/> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView1"/> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView2"/> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView3"/> 

      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView4"/> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <Button 
       android:id="@+id/btn_demo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:text="Demo" /> 

     </LinearLayout> 

    </LinearLayout> 

</ScrollView> 
+0

. Я говорил об использовании весов полностью и не использовал dp и т. д., когда я использую весы, у моего текстового обзора есть ограниченная область для показа. могу ли я выполнять такую ​​прокрутку при использовании весов. Я хочу показать полные страницы прокрученных данных. –

+0

@PrashantSinghVerma показать ваш xml, чтобы я мог вам помочь. –

Смежные вопросы