2017-07-27 29 views
0

目前我正在嘗試創建一個主要是horizo​​ntalscrollview和主視圖的小應用程序。 horizo​​ntalscrollview包含一個線性佈局,在我的BoxItem.axml文件中定義了一堆BoxItem。一個BoxItem也顯示在主視圖上。在axml或c中縮放視圖#

問題是我需要縮小項目以適合滾動視圖。我希望項目自動調整大小(及其所有子視圖)以適合父視圖(高度)。

如果可能的話,我還想實現一個函數set代碼的大小(但這不是我主要關心的)。

BoxItem.axml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/Box" 
    android:gravity="center_vertical"> 
    <TextView 
     android:text="Shelf" 
     android:id="@+id/Shelf" 
     android:textColor="#009900" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="30sp" /> 
    <TextView 
     android:text="ProductName" 
     android:id="@+id/Name" 
     android:textColor="#009900" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="30sp" /> 
    <TextView 
     android:text="Barcode" 
     android:id="@+id/Barcode" 
     android:textColor="#009900" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="30sp" /> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout3" 
     android:gravity="center"> 
     <TextView 
      android:text="10" 
      android:id="@+id/StockCurrent" 
      android:textColor="#009900" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:textSize="30sp" /> 
     <TextView 
      android:text="/" 
      android:id="@+id/textView4" 
      android:textColor="#009900" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:textSize="30sp" /> 
     <TextView 
      android:text="10" 
      android:id="@+id/StockMax" 
      android:textColor="#009900" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:textSize="30sp" /> 
    </LinearLayout> 
</LinearLayout> 

回答

0

我想的項目(及其所有子視圖)會自動調整大小以適應parentview(高)。

您需要使用API​​ 11或更高版本來調整View。像這樣的使用方法:

LinearLayout ll = FindViewById<LinearLayout>(Resource.Id.Box); 
float scalingFactor = 0.5f; // scale down to half the size 
ll.ScaleX = scalingFactor; 
ll.ScaleY = scalingFactor; 

但是尺寸大小很難計算。

另一種選擇,建議使用CardView來實現此功能。

+0

@ b.holz,你解決了你的問題嗎? –