android gravity and LinerarLayout for state

755 ワード

gravityという英語の単語は重心の意味で、ここでは停泊位置の意味を表します.
android:layout_gravityとandroid:gravityの違い
名前からandroid:gravityは要素自体について話しており、要素自体のテキストはどこに表示されているかで属性設定が変わりますが、デフォルトは左側に設定されていません.
android:layout_gravityは、その親要素に対して、要素が親要素のどこに表示されるかを説明します.
例えばbutton:android:layout_gravityはボタンのインタフェース上の位置を表します.android:gravityはbutton上の字のbutton上の位置を表す.
I ran into this problem just now. You'll have to set the LinearLayout to clickable. You can either do this in the XML with
android:clickable="true"

Or in code with
yourLinearLayout.setClickable(true);