我已將屏幕分爲4個水平和兩個垂直部分。我使用線性佈局顯示ImageView和TextView。我無法將圖像視圖精確設置在線性佈局的中心。設置圖像正好在中心
home_layout
<?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">
<include layout="@layout/appbar_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#156C7F"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="125dp"
android:text="Branch Office : Dhankuta"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<View
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:background="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:text="Tuesday - 4 April, 2017"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
<!-- Main Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DFDFDF"
android:orientation="vertical">
<!-- first Frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- first row first column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="@mipmap/saving"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Saving Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<!-- first row second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView **i have made changes here**
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="@mipmap/loancollection"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Loan Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 2nd frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Second row first column -->
<LinearLayout **i have made changes here**
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="@mipmap/dailysaving"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Daily Saving"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
/>
</LinearLayout>
<!-- Second row Second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="@mipmap/memberenrollment"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Member Enrollment"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 3rd frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Third row First column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="@mipmap/cashincashout"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Cash In-Out "
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Third row Second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="@mipmap/collectorledger"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Collector Ledger "
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 4th frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Fourth row First column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="@mipmap/summary"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Summary"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Fourth row Second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="@mipmap/officesync"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Office Sync"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 4th frame end -->
</LinearLayout> <!-- main frame end Layout -->
</LinearLayout>
我已經對第一行第一列的第一行第二列的變化
**我想要的ImageView恰好位於的中心線性佈局,然後文本將在剩餘部分進行調整。**如何解決此問題?
我建議你使用**相對佈局**代替。它容易與相對佈局 – Pzy64
不能有任何替代線性佈局? – Ghimire
爲什麼每個圖像需要「頂部|中心」?如果你想在LinearLayout中設置中心,只需設置android:layout_gravity =「center」 否則,我們可以使用RelativeLayout –