所以,我正在创建一个锻炼应用程序并且遇到imageButtons和文本的问题。
content_app_layout_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="hr.app.liftme.liftmehr.AppLayoutMain"
android:orientation="vertical"
tools:showIn="@layout/activity_app_layout_main"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gornjiLayoutIkone"
android:layout_marginBottom="5dp"
android:layout_marginTop="50dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonVjezbe"
android:background="@drawable/ikona_vjezbe"
android:layout_weight="1"
android:layout_marginRight="8dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonProgramiTreninga"
android:background="@drawable/ikona_programi"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:onClick="ProgramiTreninga"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonPopisTeretana"
android:background="@drawable/ikona_popisteretana"
android:layout_weight="1"
android:layout_marginLeft="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/gornjiLayoutIkone"
android:id="@+id/gornjiLayoutImena"
android:layout_marginBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Vježbe"
android:id="@+id/textViewVjezbe"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Programi \n treninga"
android:id="@+id/textViewProgramiTreninga"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Popis \n teretana"
android:id="@+id/textViewPopisTeretana"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/gornjiLayoutImena"
android:id="@+id/srednjiLayoutIkone"
android:layout_marginBottom="5dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonPrehrana"
android:layout_weight="1"
android:layout_marginRight="8dp"
android:background="@drawable/ikona_prehrana" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonDodaciPrehrani"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/ikona_dodaciprehrani" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonTrgovineSportskomPrehranom"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:background="@drawable/ikona_popistrgovina" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/srednjiLayoutIkone"
android:layout_marginBottom="5dp"
android:id="@+id/srednjiLayoutImena">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Prehrana"
android:id="@+id/textViewPrehrana"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Dodaci \n prehrani"
android:id="@+id/textViewDodaciPrehrani"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Trgovine \n sportskom \n prehranom"
android:id="@+id/textViewTrgovineSportskomPrehranom"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/srednjiLayoutImena"
android:id="@+id/donjiLayoutIkone"
android:layout_marginBottom="5dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonSavjeti"
android:layout_weight="1"
android:layout_marginRight="8dp"
android:background="@drawable/ikona_savjeti"
android:onClick="Savjeti"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonKalkulatori"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/ikona_kalkulatori" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonKontakt"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:background="@drawable/ikona_kontakt"
android:onClick="Kontakt"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/donjiLayoutIkone"
android:id="@+id/donjiLayoutImena">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Savjeti"
android:id="@+id/textViewSavjeti"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Kalkulatori"
android:id="@+id/textViewKalkulatori"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Kontakt"
android:id="@+id/textViewKontakt"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</ScrollView>
如您所见,主要布局图标正常,只有文本未正确排列。我不知道我应该使用布局:边距来对齐它们,我认为这不会很好,因为各种屏幕尺寸。当连续3个时,图标看起来很好。
content_programi_treninga.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="hr.app.liftme.liftmehr.ProgramiTreninga"
tools:showIn="@layout/activity_programi_treninga">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonProgramiBodybuilding"
android:background="@drawable/ikona_programi_bodybuilding"
android:layout_weight="1"
android:adjustViewBounds="false"
android:layout_marginRight="15dp"
android:onClick="ProgramiBodybuilding"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/imageButtonProgramiPowerlifting"
android:background="@drawable/ikona_programi_powerlifting"
android:layout_weight="1"
android:adjustViewBounds="false"
android:layout_marginLeft="15dp"
android:onClick="ProgramiPowerlifting"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout"
android:id="@+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Bodybuilding"
android:id="@+id/textViewProgramiBodybuilding"
android:textColor="#000000"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:onClick="ProgramiBodybuilding"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Powerlifting"
android:id="@+id/textView8"
android:textColor="#000000"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:onClick="ProgramiPowerlifting"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:id="@+id/linearLayout3">
<ImageButton
android:layout_width="115dp"
android:layout_height="115dp"
android:id="@+id/imageButtonPowerbuilding"
android:background="@drawable/ikona_programi_powerbuilding"
android:layout_weight="0"
android:layout_marginTop="10dp"
android:onClick="ProgramiPowerBuilding"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/linearLayout3"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Power \nBuilding"
android:id="@+id/textView7"
android:textColor="#000000"
android:gravity="center" />
</LinearLayout>
</RelativeLayout>
正如你所看到的,连续2个看起来并不好看。 我创建了各种图标大小,从ldpi屏幕到xxxhdpi屏幕,当我在布局编辑器上添加它们时,它们非常小,所以我使用layout:height来纠正它。但由于屏幕尺寸不同,我认为这不是一个好主意。
所以我的问题是,我应该怎么做才能解决这个问题,以便完全对齐和图像按钮大而且比例为1:1?
如果您需要我上传一些代码,请告诉我代码,我会尽快上传!
谢谢!