We are using GridLayout and the firstrow(in bold) is not visible in the below xml.
Only first TextView is not visible.All other texts are visible.
Would be very helpful if someone helped us on this. Thanks in Advance
API level is 21
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:alignmentMode="alignMargins"
android:background="#drawable/gradientbg"
android:columnCount="2"
android:orientation="horizontal"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="?attr/actionBarSize"
android:rowCount="8"
android:useDefaultMargins="true"
tools:context="com.example.truesolution.Page2" >
<TextView
android:id="#+id/display_message2"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_row="0"
android:text="#string/Sessions"
android:visibility="visible" />
<Button
android:layout_width="278dp"
android:layout_height="72dp"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_row="1"
android:onClick="sendMessage"
android:text="#string/Value" />
<TextView
android:id="#+id/display_message3"
android:layout_column="0"
android:layout_row="2"
android:textColor="#color/text_color"
android:text="#string/Licensing" />
<Button
android:layout_width="132dp"
android:layout_column="0"
android:layout_row="3"
android:onClick="sendMessage"
android:text="#string/Value" />
<TextView
android:id="#+id/display_message4"
android:layout_column="0"
android:layout_row="4"
android:textColor="#color/text_color"
android:text="#string/DesktopFailures" />
<Button
android:layout_width="131dp"
android:layout_column="0"
android:layout_row="5"
android:onClick="sendMessage"
android:text="#string/Value" />
</GridLayout>
Related
I need to use GridLayout to display two buttons. One and second one with twice the width of other button. I want the NEXT button be twice the width of BACK button and I need a GridLayout.
My source code is as below:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="#style/Calculator.Grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3"
app:rowCount="1">
<Button
android:id="#+id/button_back"
android:layout_column="0"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_gravity="left|top"
android:background="#drawable/bg_back_button"
android:text="#string/back"
android:textColor="?attr/colorTextSecondary"
android:textSize="16sp" />
<Button
android:id="#+id/button_next"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_gravity="fill"
android:background="#drawable/bg_next_button"
android:text="#string/next"
android:textColor="?attr/colorTextPrimary"
android:textSize="16sp" />
</GridLayout>
Desired display (NEXT Button should be double the width of BACK button) :
But the result is (Problem) :
If you don't have any problem with Linear Layout as inner container then use this
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="#style/Calculator.Grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="3"
app:rowCount="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_back"
android:layout_column="0"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_gravity="left|top"
android:background="#drawable/bg_back_button"
android:text="#string/back"
android:textColor="?attr/colorTextSecondary"
android:textSize="16sp"
android:layout_weight="2"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_next"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_gravity="fill"
android:background="#drawable/bg_next_button"
android:text="#string/next"
android:textColor="?attr/colorTextPrimary"
android:textSize="16sp"
android:layout_weight="1"/>
</LinearLayout>
</GridLayout>
This is work my bro try this
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="3"
android:rowCount="3">
<Button
android:id="#+id/textViewNW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_gravity="center|fill"
android:layout_rowSpan="1"
android:layout_rowWeight="1"
android:background="#fe4141"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/textViewNE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_gravity="center|fill"
android:layout_rowSpan="2"
android:layout_rowWeight="2"
android:background="#51f328"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />
</GridLayout>
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="#style/Calculator.Grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="3"
app:rowCount="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/button_back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_gravity="left|top"
android:layout_weight="2"
android:background="#drawable/bg_back_button"
android:text="#string/back"
android:textColor="?attr/colorTextSecondary"
android:textSize="16sp" />
<Button
android:id="#+id/button_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_gravity="fill"
android:layout_weight="1"
android:background="#drawable/bg_next_button"
android:text="#string/next"
android:textColor="?attr/colorTextPrimary"
android:textSize="16sp" />
</LinearLayout>
</GridLayout>
The build of my custom list row looks fine, but when I run the app the text fields on the right appear off the screen. API 23.
Here is the listview
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.archerdx.fusionlibrary.FusionList">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fusionListView">
</ListView>
</RelativeLay
out>
And here is the xml file of the custom rows I'm using
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
android:rowCount="4"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="384dp"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/fusionName"
android:layout_gravity="fill_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_row="0"
android:layout_column="0"
android:layout_columnSpan="3"
android:textColor="#5987c6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sources"
android:id="#+id/textView"
android:layout_row="1"
android:layout_column="0"
android:textSize="22dp"
android:layout_gravity="center|left"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:textColor="#000000" />
<TextView
android:layout_width="154dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/sourceName"
android:layout_weight="0.06"
android:layout_row="1"
android:layout_column="1"
android:layout_columnSpan="2"
android:gravity="right|center_vertical"
android:layout_marginRight="5dp"
android:textColor="#5987c6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Number of References"
android:id="#+id/textView2"
android:layout_row="2"
android:layout_column="0"
android:textSize="22dp"
android:layout_gravity="center|left"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:singleLine="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/numberOfReferences"
android:layout_gravity="fill_horizontal"
android:layout_row="2"
android:layout_column="1"
android:layout_columnSpan="2"
android:gravity="right|center_vertical"
android:textIsSelectable="true"
android:layout_marginRight="5dp"
android:textColor="#5987c6" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:id="#+id/button"
android:layout_weight="0.03"
android:layout_row="3"
android:layout_column="0"
android:layout_marginLeft="20dp" />
</GridLayout>
Give the width to your textviews wrap_content. Or if you want to show in single line the use this in your textviews:
android:ellipsize="end"
android:singleLine="true"
You're using fixed layout widths, weights and a gridview which is never going to be a flexible solution.
Look in to using Linear or Relative layouts instead. There's plenty of info out there.
I want to have this layout structure:
I achieved this with many nested LinearLayouts and nested weights, but I can see that this is really bad for performance. Has anyone an idea how to get such an layout?
I should also say, that it should be above the whole screen.
You can create the layout like this using table layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="4"
android:orientation="horizontal"
android:rowCount="8" >
<Button
android:layout_columnSpan="4"
android:layout_gravity="fill"
android:text="1" />
<Button
android:layout_columnSpan="4"
android:layout_gravity="fill"
android:text="2" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<LinearLayout
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="4"
android:layout_rowSpan="5"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="side"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="side"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="side"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="side"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="side"/>
</LinearLayout>
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
<Button
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:text="3" />
</GridLayout>
If you have any comment it. I am glad to answer you.
<?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="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEXTVIEW"
android:layout_marginTop="10dip"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dip"
android:text="TEXTVIEW" />
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:horizontalSpacing="40dp"
android:numColumns="4"
android:verticalSpacing="10dp"
android:visibility="visible" />
</LinearLayout>
I am new at developing Android app.I have 4 EditText corresponding 4 TextView.but I have a problem with EditTexts,they dont fit properly.How can I handle this problem.Following is my xml layout file.Please help me,what is wrong.Thank you in advance.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.mobilecoursemanagementsystem.AddCourseActivity"
android:orientation="vertical">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="5"
android:columnCount="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Course Title"
android:layout_column="0"
android:layout_row="0"
android:id="#+id/txtTitle"/>
<!--android:layout_marginTop="10dp"-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_marginTop="10dp"
android:id="#+id/editTitle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_marginTop="10dp"
android:text="Course Code"
android:id="#+id/txtCode"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_marginTop="10dp"
android:id="#+id/editCode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:layout_marginTop="10dp"
android:text="Number of Student"
android:id="#+id/txtNumberOfSts"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_marginTop="10dp"
android:id="#+id/editNumberOfSts" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:layout_marginTop="10dp"
android:text="Course Level"
android:id="#+id/txtLevel"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:layout_marginTop="10dp"
android:id="#+id/editLevel" />
</GridLayout>
</LinearLayout>
click for Screenshoot
user layout_margins in your layout for every edittext
android:layout_marginRight="10dp"
set whatever value you like for margin
I have a simple ListView:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/overvieList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and this layout for the ListView items:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="2" >
<ImageView
android:id="#+id/overviewItemImage"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_marginRight="5dp"
android:layout_row="0"
android:src="#drawable/ic_launcher" />
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="left|top"
android:layout_row="0"
android:layout_marginLeft="3dp"
android:layout_marginRight="5dp"
android:columnCount="1"
android:rowCount="3" >
<TextView
android:id="#+id/overviewItemHeader"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="0"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/overviewItemCategory"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10sp"
android:textStyle="italic" />
<TextView
android:id="#+id/overviewItemText"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="2"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</GridLayout>
</GridLayout>
</LinearLayout>
Now i use a modified ArrayAdapter to fill the ListView.
ok that works.
But how can I prevent it that the TextViews Content (on the right) goes over the edge??
set layout_marginRight in textview . i hope this will solve your problem
just add a little margin android:layout_marginRight="5dp" to your TextViews