Jak utworzyć obramowanie wokół LinearLayout systemu Android?
Mam jeden duży układ i jeden mniejszy układ wewnątrz.
Jak utworzyć obramowanie linii wokół małego układu?
7 answers
Jasne. Możesz dodać obramowanie do dowolnego układu. Zasadniczo musisz utworzyć niestandardowy rysowalny i dodać go jako tło do układu. przykład:
Utwórz plik o nazwie customborder.xml
w folderze drawable:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<stroke android:width="1dp" android:color="#CCCCCC"/>
</shape>
Teraz zastosuj go jako tło do mniejszego układu:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/customborder">
To powinno wystarczyć.
Zobacz też:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-05 08:55:57
Creat XML o nazwie border.xml w folderze drawable jak poniżej:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
Następnie dodaj to do układu liniowego jako backgound jak to:
android:background="@drawable/border"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-27 11:56:54
Spróbuj tego:
Na przykład zdefiniujmy res/drawable / my_custom_background.xml as:
(Utwórz ten układ w folderze drawable) layout_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="2dp" android:height="2dp"
android:color="#FF0000" />
<solid android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
<corners android:radius="1dp" android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp" android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
</layer-list>
Main.xml
<LinearLayout
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/layout_border" />
</LinearLayout>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-27 12:00:09
Utwórz jeden plik xml w folderze drawable
<stroke
android:width="2dp"
android:color="#B40404" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners android:radius="4dp" />
Teraz wywołaj ten xml do tła Twojego małego układu
Android: background= "@drawable / yourxml "
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-28 06:38:10
To rozwiązanie doda tylko obramowanie, ciało LinearLayout będzie przezroczyste.
Najpierw Utwórz tę ramkę drawable w folderze drawable, border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#ec0606"/>
<corners android:radius="10dp"/>
</shape>
Następnie w widoku LinearLayout dodaj obramowanie.xml jako tło w ten sposób
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/border">
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-24 15:18:48
Dodam Link Android docs do innych odpowiedzi.
Https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Opisuje wszystkie atrybuty kształtu Drawable i stroke
wśród nich ustawić obramowanie.
Przykład:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#F00"/>
<solid android:color="#0000"/>
</shape>
Czerwona ramka z przezroczystym tłem.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-14 14:33:35
Możesz to zrobić pragmatycznie również
GradientDrawable gradientDrawable=new GradientDrawable();
gradientDrawable.setStroke(4,getResources().getColor(R.color.line_Input));
Następnie Ustaw tło układu jako:
LinearLayout layout = (LinearLayout ) findViewById(R.id.ayout); layout .setBackground(gradientDrawable);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-30 05:47:09