2016-09-28 71 views
0

我想創建一個android layout,其中有一個imageview和兩列textview直接在scrollview中的右邊。問:與多個TextViews相鄰的Android Imagview

想像一個用戶個人資料圖片和基本信息佈局。

我已經創建了一個我想要實現的線框,不幸的是我似乎無法得到imageview - textview - textview正確的佈局。

我所做的一切。

enter image description here

編輯 這是我已經沒有運氣嘗試:

<?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:scrollbars="none" 
    android:layout_weight="1"> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:weightSum="1" 
     android:orientation="horizontal"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:weight="0.4" 
      android:src="@drawable/profileImg" /> 
     <LinearLayout 
      android:weight="0.6" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:weightSum="1" 
      android:orientation="vertical"> 
      <RelativeLayout 
       android:weight="0.25"> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="User ID" 
        android:textColor="#fff" /> 
       <TextView 
        android:id="@+id/pUID" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="pUID" 
        android:textColor="#fff" /> 
      </RelativeLayout> 
      <RelativeLayout 
       android:weight="0.25"> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="Full Name" 
        android:textColor="#fff" /> 
       <TextView 
        android:id="@+id/fName" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="fName" 
        android:textColor="#fff" /> 
      </RelativeLayout> 
      <RelativeLayout 
       android:weight="0.25"> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="Age" 
        android:textColor="#fff" /> 
       <TextView 
        android:id="@+id/pAge" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="pAge" 
        android:textColor="#fff" /> 
      </RelativeLayout> 
      <RelativeLayout 
       android:weight="0.25"> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="Date of Birth" 
        android:textColor="#fff" /> 
       <TextView 
        android:id="@+id/pDOB" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="10sp" 
        android:text="pDOB" 
        android:textColor="#fff" /> 
      </RelativeLayout> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
+0

顯示你的XML代碼。 –

+0

顯示內容...發佈您的XML文件或其他東西... – Aspicas

+0

@Aspicas我添加了一些axml – jaymarvels

回答

1

嘗試使用下一個XML file

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

    <ScrollView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="none"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center_vertical|center_horizontal" 
       android:layout_marginTop="20dp" 
       android:layout_marginBottom="20dp"> 

       <TextView 
        android:text="TextView" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/textView48" 
        android:textSize="24sp"/> 
      </LinearLayout> 

      <LinearLayout 
       android:weight="0.6" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal"> 

       <LinearLayout 
        android:orientation="horizontal" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="0.30"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:weight="0.4" 
         android:src="@drawable/profileImg" 
         android:layout_marginLeft="10dp"/> 
       </LinearLayout> 

       <LinearLayout 
        android:weight="0.25" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="0.70"> 

        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_weight="1"> 

         <LinearLayout 
          android:weight="0.25" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:layout_marginLeft="10dp"> 
          <TextView 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:text="TextView" 
           android:textColor="#000" 
           android:textSize="24sp"/> 
         </LinearLayout> 

         <LinearLayout 
          android:weight="0.25" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:layout_marginLeft="10dp"> 
          <TextView 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:textSize="24sp" 
           android:text="TextView" 
           android:textColor="#000" /> 
         </LinearLayout> 

         <LinearLayout 
          android:weight="0.25" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:layout_marginLeft="10dp"> 
          <TextView 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:textSize="24sp" 
           android:text="TextView" 
           android:textColor="#000" /> 
         </LinearLayout> 
        </LinearLayout> 

        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_weight="1"> 

         <LinearLayout 
          android:weight="0.25" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:layout_marginLeft="10dp"> 
          <TextView 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:text="TextView" 
           android:textColor="#000" 
           android:textSize="24sp"/> 
         </LinearLayout> 

         <LinearLayout 
          android:weight="0.25" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:layout_marginLeft="10dp"> 
          <TextView 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:textSize="24sp" 
           android:text="TextView" 
           android:textColor="#000" /> 
         </LinearLayout> 

         <LinearLayout 
          android:weight="0.25" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:layout_marginLeft="10dp"> 
          <TextView 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:textSize="24sp" 
           android:text="TextView" 
           android:textColor="#000" /> 
         </LinearLayout> 
        </LinearLayout> 

       </LinearLayout> 
      </LinearLayout> 

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

       <LinearLayout 
        android:orientation="horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:gravity="center_vertical|center_horizontal"> 

        <TextView 
         android:text="TextView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/textView83" 
         android:layout_marginBottom="20dp" 
         android:layout_marginTop="20dp" 
         android:textSize="18sp"/> 

       </LinearLayout> 

      </LinearLayout> 

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

       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center_vertical|center_horizontal"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextViewb" 
         android:textColor="#000" 
         android:textSize="24sp"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextViewc" 
         android:textColor="#000" 
         android:textSize="24sp" 
         android:layout_marginTop="20dp"/> 
       </LinearLayout> 

       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center_vertical|center_horizontal"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextViewd" 
         android:textColor="#000" 
         android:textSize="24sp"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextViewe" 
         android:textColor="#000" 
         android:textSize="24sp" 
         android:layout_marginTop="20dp"/> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

輸出

one

+0

這是一個相當不錯的工作示例。有沒有辦法預先定義imageview的大小?看起來大小目前是基於圖像。 – jaymarvels

+0

mmm它應該適應所有圖像...您可以通過wrap_content或match_parent對圖像高度/寬度屬性更改值,或者更改上述Linear_layout上的'layout_weight' – Aspicas

0

RelativeLayoutImageView和2 LinearLayoutLinearLayouts將包含TextViews

ImageView將是allignParentLeft而其他兩個佈局的權重爲1,佈局在圖像視圖的左側。