In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Android component LinearLayout". In daily operation, I believe many people have doubts about how to use Android component LinearLayout. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use Android component LinearLayout". Next, please follow the editor to study!
Overview
LinearLayout is a linear layout component in which components are sorted and distributed by column or row (that is, vertical or horizontal).
Common XML configuration properties (1) android:orientation
How to set LinearLayout container layout components: only values can be horizontal (horizontal), vertical (vertical)
(2) android:gravity
Sets the alignment of components for the layout within the LinearLayout container.
Values include top, bottom, left, right, center, start, end (top, bottom, left, right, center, start, end)
(3) attributes inherited in View
(including android:background, android:visibility, etc.) There are also some intervals that improve the beauty of placing components)
1. Android:layout_width and android:layout_height (match_parent/wrap_content)
2. Android: layout_gravity sets the layout of components in the container
3. Android:layout_weight sets the ratio of the spare display space occupied by the component
4. Android:layout_margin, android:layout_marginTop, android:layout_marginBottom, android:layout_marginLeft, android:layout_marginRight set the outer boundary of the component, similar to the use of margin in our web design HTML/CSS.
Code example
Activity_main.xml
MainActivity.java
Package com.example.android_demo02; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;import android.view.Gravity;import android.widget.LinearLayout;import android.widget.RadioGroup; public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {private RadioGroup orientation; private RadioGroup gravity; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); orientation= (RadioGroup) findViewById (R.id.orientation) Orientation.setOnCheckedChangeListener (this); gravity= (RadioGroup) findViewById (R.id.gravity); gravity.setOnCheckedChangeListener (this);} @ Override public void onCheckedChanged (RadioGroup radioGroup, int I) {switch (I) {case R.id.horizontal: orientation.setOrientation (LinearLayout.HORIZONTAL); break Case R.id.vertical: orientation.setOrientation (LinearLayout.VERTICAL); break; case R.id.left: gravity.setGravity (Gravity.START); break; case R.id.center: gravity.setGravity (Gravity.CENTER_HORIZONTAL); break Case R.id.right: gravity.setGravity (Gravity.END); break;}}
Achieve results:
At this point, the study on "how to use Android component LinearLayout" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.