我想创建这个,我在其中使用了drawable和textview:
但是我没有将textview置于中心,也不会因填充而看到整个文本。如何更改现有代码,使其如下所示。现在我不想要图像,只需要文本和按钮。
rounded_edge.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#FFFFFF"/>
<stroke android:width="5dp"
android:color="#000000"/>
<!--<padding android:left="30dp"
android:top="350dp"
android:right="250dp"
android:bottom="10dp"/>-->
<gradient android:startColor="#D2E0E2" android:endColor="#D2E0E2"/>
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp" android:topRightRadius="5dp"/>
</shape>
yelp_biz_detail.xml
<?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="horizontal"
android:layout_centerInParent="true"
>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edge"
android:layout_marginTop="30dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:paddingLeft="30dp"
android:paddingTop="350dp"
android:paddingRight="250dp"
android:paddingBottom="10dp"/>
android:textAlignment="center"
android:gravity="center"
/>
</LinearLayout>
解决方案是:
<?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="horizontal"
android:layout_centerInParent="true"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="30dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="150dp"
android:background="@drawable/rounded_edge"
>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="30dp"
android:paddingTop="30dp"
android:paddingRight="25dp"
android:paddingBottom="10dp"
android:textAllCaps="true"
/>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:1)
我认为你的android:paddingTop="350dp"
中的35dp而不是350dp,android:paddingRight="250dp"
文件中的yelp_biz_detail.xml
中的25dp而不是250dp
答案 1 :(得分:0)
rounded_edge.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<corners android:radius="5dp" />
<padding
android:bottom="16dp"
android:left="16dp"
android:right="16dp"
android:top="16dp" />
</shape>
yelp_biz_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99000000"
android:padding="32dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="160dp"
android:layout_height="160dp"
android:src="@drawable/your_image" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/rounded_edge"
android:gravity="center"
android:text="Your text..." />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:orientation="horizontal" >
<Button
android:id="@+id/button_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="Button One" />
<Button
android:id="@+id/button_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:text="Button Two" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>